?? threadservice.java
字號:
package com.booksearch.service.process;
import java.util.ArrayList;
import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import com.booksearch.orm.Book;
import com.booksearch.service.htmlparser.HtmlParser;
import com.booksearch.util.SessionBean;
public class ThreadService extends Thread {
private String webName;
private String webUrl;
private Document doc = null;
private HtmlParser htmlParser;
private SessionBean sessionBean;
private static final Logger logger;
static
{
logger = Logger.getLogger(com.booksearch.dao.BookLoadDaoImpl.class);
}
public ThreadService(String webName,String webUrl,HtmlParser htmlParser,SessionBean sessionBean){
this.webName = webName;
this.webUrl = webUrl;
this.htmlParser = htmlParser;
this.sessionBean = sessionBean;
}
public void run(){
try {
if("tsinghua".equals(webName))
this.sleep(1000);
else
this.sleep(500);
doc = htmlParser.nekohtmlParser(webUrl);
} catch (Exception e) {
doc = null;
logger.error("==========" + webName + "請求解析" + webUrl + "時出錯" + "==========" + e);
}
if(null != doc){
if(!sessionBean.isHasupdate()){
sessionBean.addRecordNum(htmlParser.getRecordNum(doc));
}
ArrayList<Book> tempList = htmlParser.mainService(doc,false);
/*取出下一頁url*/
String nextUrl = htmlParser.getNextPageUrl(doc);
for(int k = 0;k<tempList.size();k++){
System.out.println(webName+":"+nextUrl+tempList.get(k).getBookName()
+ " dangdang:>>"+tempList.get(k).getPrice().getDangdangPrice());
}
/*對結果靜態鏈表進行同步處理,并把檢索結果存入其中*/
if(!"no".equals(nextUrl))
this.sessionBean.getNextUrl().put(webName, nextUrl);
this.sessionBean.addtempList(tempList);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -