fix thread pool

master
yihua.huang 2013-09-22 22:52:52 +08:00
parent 81f7534757
commit 3c79d031bd
3 changed files with 6 additions and 12 deletions

View File

@ -234,12 +234,15 @@ public class Spider implements Runnable, Task {
}
Request request = scheduler.poll(this);
//single thread
if (executorService == null) {
if (threadNum <= 1) {
while (request != null && stat.compareAndSet(STAT_RUNNING, STAT_RUNNING)) {
processRequest(request);
request = scheduler.poll(this);
}
} else {
synchronized (this) {
this.executorService = ThreadUtils.newFixedThreadPool(threadNum);
}
//multi thread
final AtomicInteger threadAlive = new AtomicInteger(0);
while (true && stat.compareAndSet(STAT_RUNNING, STAT_RUNNING)) {
@ -363,10 +366,11 @@ public class Spider implements Runnable, Task {
public void stop() {
stat.compareAndSet(STAT_RUNNING, STAT_STOPPED);
executorService.shutdown();
}
public void stopAndDestroy() {
stat.compareAndSet(STAT_RUNNING, STAT_STOPPED);
stop();
destroy();
}
@ -385,9 +389,6 @@ public class Spider implements Runnable, Task {
if (threadNum == 1) {
return this;
}
synchronized (this) {
this.executorService = ThreadUtils.newFixedThreadPool(threadNum);
}
return this;
}

View File

@ -44,9 +44,4 @@ public abstract class Selectors {
return new OrSelector(selectors);
}
public static void main(String[] args) {
String s = "a";
or(regex("<title>(.*)</title>"), xpath("//title"), $("title")).select(s);
}
}

View File

@ -16,8 +16,6 @@ import java.util.regex.Pattern;
*/
public class UrlUtils {
private static Pattern relativePathPattern = Pattern.compile("^([\\.]+)/");
/**
* canonicalizeUrl
*