线程池注意事项

没有引用指向且没有剩余线程的线程池将会自动关闭

public static void main(String[] args) throws Exception{
ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 1000, TimeUnit.MILLISECONDS,
new LinkedBlockingDeque<>(), new AbortPolicy());

executor.allowCoreThreadTimeOut(true);
executor.execute(() -> System.out.println("hahahah"));
}

主线程退出后,应用对象被回收,没有引用指向线程池兑现,将自动关闭

posted on 2022-05-26 14:29  一直小飞猫  阅读(25)  评论(0编辑  收藏  举报

导航