zoukankan      html  css  js  c++  java
  • MinerThreadPool.java 线程池

    MinerThreadPool.java 线程池

    package com.iteye.injavawetrust.miner;
    
    import java.util.concurrent.BlockingQueue;
    import java.util.concurrent.LinkedBlockingQueue;
    import java.util.concurrent.ThreadPoolExecutor;
    import java.util.concurrent.TimeUnit;
    
    /**
     * 线程池
     * @author InJavaWeTrust
     *
     */
    public class MinerThreadPool {
    	
    	private static volatile ThreadPoolExecutor executor = null;
    	/**
    	 * 核心池的大小
    	 */
    	private static int corePoolSize = 100;
    	/**
    	 * 线程池最大线程数
    	 */
    	private static int maximumPoolSize = 200;
    	/**
    	 * 线程没有任务执行时最多保持多久时间会终止
    	 */
    	private static long keepAliveTime = 100L;
    	/**
    	 * 参数keepAliveTime的时间单位
    	 */
    	private static TimeUnit unit = TimeUnit.SECONDS;
    	
    	private MinerThreadPool() {
    		
    	}
    	
    	public static ThreadPoolExecutor getInstance() {
    		if (null == executor) {
    			executor = getInstance(corePoolSize, maximumPoolSize, keepAliveTime, unit);
    		}
    		return executor;
    	}
    	
    	public static ThreadPoolExecutor getInstance(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit){
    		if (null == executor) {
    			synchronized (MinerThreadPool.class) {
    				BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
    				executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, queue);
    			}
    		}
    		return executor;
    	}
    	/**
    	 * shutdown
    	 */
    	public static void shutdown() {
        	if (executor != null) {
        		executor.shutdown();
        	}
        }
    
    }
    

    返回列表

  • 相关阅读:
    求职简历撰写要点和模板分享
    find命令
    MD5Init-MD5Update-MD5Final
    Linux find命令详解
    Linux进程KILL不掉的原因
    Linux操作系统的内存使用方法详细解析
    Lsof命令详解
    为什么ps中CPU占用率会有超出%100的现象?
    第12课 经典问题解析一
    第11课 新型的类型转换
  • 原文地址:https://www.cnblogs.com/muyuge/p/6152080.html
Copyright © 2011-2022 走看看