All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.qq275860560.common.util.ThreadPoolExecutorUtil Maven / Gradle / Ivy

There is a newer version: 201905061822
Show newest version
package com.github.qq275860560.common.util;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author [email protected]
 */
public class ThreadPoolExecutorUtil {
	private static Log log = LogFactory.getLog(ThreadPoolExecutorUtil.class);

	public static ThreadFactory threadFactory = new ThreadFactory() {
		@Override
		public Thread newThread(Runnable runnable) {
			return new Thread(runnable);
		}
	};
	public static ThreadPoolExecutor threadPoolExecutor = null;
	static {
		int poolSize = Runtime.getRuntime().availableProcessors() * 2 + 1;
		LinkedBlockingQueue requestQueue = new LinkedBlockingQueue(1024);
		//
		threadPoolExecutor = new ThreadPoolExecutor(poolSize, poolSize, 60L, TimeUnit.SECONDS, requestQueue,
				threadFactory);
		threadPoolExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardOldestPolicy());
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy