runthreadpool.java~2~
来自「自动格式化优盘.good,find」· JAVA~2~ 代码 · 共 37 行
JAVA~2~
37 行
package ListDisks;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
//import org.apache.log4j.Logger;
public class runThreadPool {
public static class allThread {
// static Logger log = Logger.getLogger(runThreadPool.class);
public static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(3,
5, 3, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5),
new ThreadPoolExecutor.CallerRunsPolicy());
// public static void main(Runnable task) {
public static void addRunThreadPool(Runnable task) {
// 构造一个线程池
{
try {
// 产生一个任务,并将其加入到线程池
threadPool.execute(task);
//log.info("线程激活:" + threadPool.getActiveCount() + "个");
System.out.println("线程激活:" + threadPool.getActiveCount() +
"个");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?