原文链接:http://www.cnblogs.com/MichaelYin/archive/2011/10/07/2200412.html
Heritrix是一个多线程的程序,里面使用工作线程来处理url,这些工作线程称为torThreads,这些toethread统一的被ToePool所管理,Toepool通过setSize方法来管理运行的toethread数目
00 | public void setSize( int newsize) { |
02 | int difference = newsize - getToeCount(); |
05 | for ( int i = 1; i <= difference; i++) { |
09 | // must retire extra threads |
10 | int retainedToes = targetSize; |
11 | Thread[] toes = this .getToes(); |
12 | for ( int i = 0; i < toes.length; i++) { |
13 | if (!(toes[i] instanceof ToeThread)) { |
17 | if (retainedToes >= 0) { |
18 | continue ; // this toe is spared |
21 | ToeThread tt = (ToeThread) toes[i]; |
ToeThread从Frontier中获取待处理的url,然后ToeThread对url进行一系列的处理,当所有的处理流程完成之后,调用Frontier的finished方法告知url抓取完毕,ToeThread重新获取新的url
这是ToeThread中的run方法的代码
01 | CrawlURI curi = controller.getFrontier().next(); |
11 | setStep(STEP_ABOUT_TO_RETURN_URI); |
16 | controller.getFrontier().finished(currentCuri); |
19 | 结合前面Frontier的图,可能看的就会明白一点了。 |