Commit 3c79d031 authored by yihua.huang's avatar yihua.huang

fix thread pool

parent 81f75347
......@@ -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;
}
......
......@@ -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);
}
}
\ No newline at end of file
......@@ -16,8 +16,6 @@ import java.util.regex.Pattern;
*/
public class UrlUtils {
private static Pattern relativePathPattern = Pattern.compile("^([\\.]+)/");
/**
* canonicalizeUrl
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment