📄 runthreadpool.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -