日期:2014-05-18 浏览次数:20771 次
public class WebPageAnalyzer implements Runnable{
int start =0;int end = 0;int index = 0;
public DataDao da = DataDao.createDao();
public static List<Page> pageList;
.......
public static void main(String[] args)
{
pageList = wpa.da.getUnAnalysedPages();
if(pageList.size()>0)
{
System.out.println(new Date()+" Found " + pageList.size() + " unanalynized pages.");
System.out.println("Start analysising for " +pageList.size() + " pages ...");
try {
ExecutorService executorService = Executors.newCachedThreadPool();
for (int i =0; i < 5; i++) {
executorService.execute(new WebPageAnalyzer(i*200,Math.min((i+1)*200,pageList.size()),i+1));
if((i+1)*200>pageList.size()){break;}
}
executorService.shutdown();
while (!executorService.awaitTermination(60, TimeUnit.SECONDS)) { System.out.println("还有线程在忙活~~wait!!!!");}
System.out.println("Finished all threads");
} catch (Exception e) {
e.printStackTrace();
}
}
}