wg-basic/basic-util/src/main/java/ink/wgink/util/thread/CachedThreadPoolUtil.java

41 lines
969 B
Java
Raw Normal View History

2022-05-20 10:13:23 +08:00
package ink.wgink.util.thread;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* @ClassName: CachedThreadPoolUtil
* @Description: 缓存线程池
* @Author: wanggeng
* @Date: 2022/5/20 00:27
* @Version: 1.0
*/
public class CachedThreadPoolUtil {
private static final Logger LOG = LoggerFactory.getLogger(CachedThreadPoolUtil.class);
/**
* 最多66个线程保持60s
*/
private static ExecutorService executorService = new ThreadPoolExecutor(0, 66,
60L, TimeUnit.SECONDS,
new SynchronousQueue<>());
/**
* 执行线程
*
* @param runnable
*/
public static void execute(Runnable runnable) {
LOG.debug("****************** execute");
executorService.execute(runnable);
}
}