⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threadservice.java

📁 本系统实现了从五个网站上搜索的图书进行整合后
💻 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 + -