optimize long compare
parent
ed3f3583cc
commit
c18b603399
|
@ -4,6 +4,7 @@ import org.apache.http.annotation.ThreadSafe;
|
|||
import org.apache.log4j.Logger;
|
||||
import us.codecraft.webmagic.Request;
|
||||
import us.codecraft.webmagic.Task;
|
||||
import us.codecraft.webmagic.utils.NumberUtils;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
|
@ -30,14 +31,14 @@ public class PriorityScheduler implements Scheduler {
|
|||
private PriorityBlockingQueue<Request> priorityQueuePlus = new PriorityBlockingQueue<Request>(INITIAL_CAPACITY, new Comparator<Request>() {
|
||||
@Override
|
||||
public int compare(Request o1, Request o2) {
|
||||
return -(new Long(o1.getPriority()).compareTo(o2.getPriority()));
|
||||
return -NumberUtils.compareLong(o1.getPriority(), o2.getPriority());
|
||||
}
|
||||
});
|
||||
|
||||
private PriorityBlockingQueue<Request> priorityQueueMinus = new PriorityBlockingQueue<Request>(INITIAL_CAPACITY, new Comparator<Request>() {
|
||||
@Override
|
||||
public int compare(Request o1, Request o2) {
|
||||
return -(new Long(o1.getPriority()).compareTo(o2.getPriority()));
|
||||
return -NumberUtils.compareLong(o1.getPriority(), o2.getPriority());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package us.codecraft.webmagic.utils;
|
||||
|
||||
/**
|
||||
* @author yihua.huang@dianping.com
|
||||
*/
|
||||
public abstract class NumberUtils {
|
||||
|
||||
public static int compareLong(long o1, long o2) {
|
||||
if (o1 < o2) {
|
||||
return -1;
|
||||
} else if (o1 == o2) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package us.codecraft.webmagic.model.samples;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import us.codecraft.webmagic.Site;
|
||||
import us.codecraft.webmagic.Task;
|
||||
import us.codecraft.webmagic.model.OOSpider;
|
||||
|
@ -26,7 +25,10 @@ public class OschinaBlog{
|
|||
private List<String> tags;
|
||||
|
||||
public static void main(String[] args) {
|
||||
OOSpider.create(Site.me().setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36").addStartUrl("http://my.oschina.net/flashsword/blog").setSleepTime(0).setHttpProxy(new HttpHost("127.0.0.1",8888))
|
||||
OOSpider.create(Site.me()
|
||||
.setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36").addStartUrl("http://my.oschina.net/flashsword/blog")
|
||||
.setSleepTime(0)
|
||||
.setRetryTimes(3)
|
||||
,new PageModelPipeline() {
|
||||
@Override
|
||||
public void process(Object o, Task task) {
|
||||
|
|
Loading…
Reference in New Issue