public class ThreadPoolTest {
public static void main(String[] args) {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 2, 10,
TimeUnit.MINUTES, new ArrayBlockingQueue<>(3),new ThreadPoolExecutor.AbortPolicy());
threadPoolExecutor.execute(()->{
System.out.println(Thread.currentThread().getName()+" 输出");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
threadPoolExecutor.execute(()->{
System.out.println(Thread.currentThread().getName()+" 输出");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
threadPoolExecutor.execute(()->{
System.out.println(Thread.currentThread().getName()+" 输出");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
threadPoolExecutor.execute(()->{
System.out.println(Thread.currentThread().getName()+" 输出");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
threadPoolExecutor.execute(()->{
System.out.println(Thread.currentThread().getName()+" 输出");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
threadPoolExecutor.execute(()->{
System.out.println(Thread.currentThread().getName()+" 输出");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
threadPoolExecutor.shutdown();
}
}
线程池
最新推荐文章于 2025-03-15 16:39:01 发布