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() + "]");
    	}
    
    }
    

    返回列表

  • 相关阅读:
    在 Zabbix 中增加对磁盘性能的监控
    一些实用的php库
    虚拟化—Docker解决方案
    linux创建root也不能访问的文件夹
    mysql5.5升级5.6
    xtrabackup部分备份数据库 Partial Backups
    mysql计划任务
    mysql单机多实例
    mysql数据类型优化
    linux手工释放内存
  • 原文地址:https://www.cnblogs.com/muyuge/p/6152081.html
Copyright © 2011-2022 走看看