fix thread pool
parent
81f7534757
commit
3c79d031bd
|
@ -234,12 +234,15 @@ public class Spider implements Runnable, Task {
|
||||||
}
|
}
|
||||||
Request request = scheduler.poll(this);
|
Request request = scheduler.poll(this);
|
||||||
//single thread
|
//single thread
|
||||||
if (executorService == null) {
|
if (threadNum <= 1) {
|
||||||
while (request != null && stat.compareAndSet(STAT_RUNNING, STAT_RUNNING)) {
|
while (request != null && stat.compareAndSet(STAT_RUNNING, STAT_RUNNING)) {
|
||||||
processRequest(request);
|
processRequest(request);
|
||||||
request = scheduler.poll(this);
|
request = scheduler.poll(this);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
synchronized (this) {
|
||||||
|
this.executorService = ThreadUtils.newFixedThreadPool(threadNum);
|
||||||
|
}
|
||||||
//multi thread
|
//multi thread
|
||||||
final AtomicInteger threadAlive = new AtomicInteger(0);
|
final AtomicInteger threadAlive = new AtomicInteger(0);
|
||||||
while (true && stat.compareAndSet(STAT_RUNNING, STAT_RUNNING)) {
|
while (true && stat.compareAndSet(STAT_RUNNING, STAT_RUNNING)) {
|
||||||
|
@ -363,10 +366,11 @@ public class Spider implements Runnable, Task {
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
stat.compareAndSet(STAT_RUNNING, STAT_STOPPED);
|
stat.compareAndSet(STAT_RUNNING, STAT_STOPPED);
|
||||||
|
executorService.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopAndDestroy() {
|
public void stopAndDestroy() {
|
||||||
stat.compareAndSet(STAT_RUNNING, STAT_STOPPED);
|
stop();
|
||||||
destroy();
|
destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,9 +389,6 @@ public class Spider implements Runnable, Task {
|
||||||
if (threadNum == 1) {
|
if (threadNum == 1) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
|
||||||
this.executorService = ThreadUtils.newFixedThreadPool(threadNum);
|
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,9 +44,4 @@ public abstract class Selectors {
|
||||||
return new OrSelector(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 {
|
public class UrlUtils {
|
||||||
|
|
||||||
private static Pattern relativePathPattern = Pattern.compile("^([\\.]+)/");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* canonicalizeUrl
|
* canonicalizeUrl
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue