Skip to content

Commit 84307d0

Browse files
committed
test for one thread
1 parent 65d7dc8 commit 84307d0

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/main/java/MultiSpider.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import java.util.concurrent.Executors;
55
import java.util.concurrent.Future;
66

7+
import org.apache.log4j.Logger;
8+
import org.apache.log4j.PropertyConfigurator;
9+
710
import scheduler.DispatchScheduler;
811
import downloader.HttpClientDownloader;
912

@@ -13,22 +16,29 @@ public class MultiSpider {
1316
private ExecutorService service;
1417
private String username;
1518
private String password;
16-
private DispatchScheduler scheduler;
19+
private static DispatchScheduler scheduler;
20+
private static Logger myLog;
1721

1822
public MultiSpider create(String username, String password) {
23+
PropertyConfigurator.configure("test.log");
24+
myLog = Logger.getLogger(MultiSpider.class);
25+
myLog.debug("开始创建MultiSpider");
1926
this.username = username;
2027
this.password = password;
2128
HttpClientDownloader.init(username, password);
2229
scheduler = new DispatchScheduler();
2330
scheduler.startProcess();
31+
myLog.debug("MultiSpider创建完毕");
2432
return new MultiSpider();
2533
}
2634

2735
public void run() {
36+
myLog.debug("正式开始爬虫");
2837
service = Executors.newFixedThreadPool(this.threadNum);
2938
Future future = service.submit(new Callable() {
3039

3140
public Object call() throws Exception {
41+
myLog.debug("进入Executors模块,准备进入taskProcceed方法");
3242
scheduler.taskProcceed();
3343
return null;
3444
}
@@ -40,4 +50,9 @@ public MultiSpider thread(int num) {
4050
this.threadNum = num;
4151
return this;
4252
}
53+
54+
public static void main(String[] args) {
55+
MultiSpider spider = new MultiSpider();
56+
spider.create("tanghaodong25@163.com", "thd04180015").run();;
57+
}
4358
}

0 commit comments

Comments
 (0)