fix thread pool
parent
81f7534757
commit
3c79d031bd
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,8 +16,6 @@ import java.util.regex.Pattern;
|
|||
*/
|
||||
public class UrlUtils {
|
||||
|
||||
private static Pattern relativePathPattern = Pattern.compile("^([\\.]+)/");
|
||||
|
||||
/**
|
||||
* canonicalizeUrl
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue