zoukankan      html  css  js  c++  java
  • MinerStoreThread.java 存储线程

    MinerStoreThread.java 存储线程

    package com.iteye.injavawetrust.miner;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    /**
     * 存储线程
     * @author InJavaWeTrust
     *
     */
    public class MinerStoreThread extends Thread {
    	
    	private static final Log LOG = LogFactory.getLog(MinerStoreThread.class);
    	
    	private MinerDB mdb = MinerDB.getInstance();
    	
    	private MinerConfig config = null;
    	
    	public MinerStoreThread(MinerConfig config) {
    		this.config = config;
    	}
    	
    	public void run() {
    		while(!MinerMonitorThread.done){
    			store();
    		}
    	}
    	
    	public synchronized void store(){
    		switch(config.getStoreType().getType()) {
    		case MinerConstanits.DB : dbStore(); break;
    		case MinerConstanits.FILE : fileStore(); break;
    		default : return;
    		}
    	}
    	/**
    	 * 数据库存储
    	 */
    	public synchronized void dbStore() {
    		Html html = MinerQueue.storePoll();
    		if(null == html || MinerUtil.isBlank(html.getHtml())){
    			return;
    		}
    		
    		Map<String, String> map = new HashMap<String, String>();
    		map.put("html", html.getHtml());
    		String title = MinerUtil.fileName(html.getUrl());
    		if(title == null || title.length() > 255){
    			return;
    		}
    		map.put("title", title);
    		MinerUtil.getHtmlToLocal(map);
    		
    		MinerBean bean = new MinerBean();
    		bean.setId(mdb.getUUID());
    		bean.setBatchNo(MinerUtil.getToday());
    		String path = (MinerConstanits.HTMLPATH + MinerUtil.getToday()).replaceAll("\\", "\\\\");
    		bean.setFilePath(path);
    		bean.setFileName(title);
    		String insertSql = mdb.getInsertSql(bean);
    		mdb.insert(insertSql);
    		
    		LOG.info("MinerStoreThread 当前线程[" + Thread.currentThread().getName() + "]");
    	}
    	/**
    	 * 文件存储
    	 */
    	public synchronized void fileStore() {
    		Html html = MinerQueue.storePoll();
    		if(null == html || MinerUtil.isBlank(html.getHtml())){
    			return;
    		}
    		Map<String, String> map = new HashMap<String, String>();
    		map.put("html", html.getHtml());
    		String title = MinerUtil.fileName(html.getUrl());
    		if(title == null || title.length() > 255){
    			return;
    		}
    		map.put("title", title);
    		MinerUtil.getHtmlToLocal(map);
    		LOG.info("MinerStoreThread 当前线程[" + Thread.currentThread().getName() + "]");
    	}
    
    }
    

    返回列表

  • 相关阅读:
    软件设计师经验分享
    数据库设计基本规范
    UEditor上传文件的默认地址修改
    mongoDB简单介绍及安装
    链表中倒数第k个结点
    一入python深似海--对象的属性
    stl--vector 操作实现
    android5.x加入sim1,sim2标识
    leetCode 27.Remove Element (删除元素) 解题思路和方法
    java8新增特性(一)---Lambda表达式
  • 原文地址:https://www.cnblogs.com/muyuge/p/6152081.html
Copyright © 2011-2022 走看看