44import java .util .concurrent .Executors ;
55import java .util .concurrent .Future ;
66
7+ import org .apache .log4j .Logger ;
8+ import org .apache .log4j .PropertyConfigurator ;
9+
710import scheduler .DispatchScheduler ;
811import 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