//Executors.newFixedThreadPool();//请求堆积在处理队列可能会消耗非常大的内存OOM
//Executors.newCachedThreadPool(); newScheduledThreadPool(); //默认创建线程个数为Integer.MAX_VALUE 数量非常大,可能OOM
//ExecutorService service = Executors.newFixedThreadPool(3);
//Executors.newCachedThreadPool(); newScheduledThreadPool(); //默认创建线程个数为Integer.MAX_VALUE 数量非常大,可能OOM
//ExecutorService service = Executors.newFixedThreadPool(3);
ExecutorService service = new ThreadPoolExecutor(3,3,1,TimeUnit.SECONDS,new ArrayBlockingQueue<Runnable>(2));
本文探讨了Java中线程池的合理配置方法,强调了避免因不当配置而导致的内存溢出问题。通过具体示例说明如何设置线程池参数以确保系统的稳定运行。
568

被折叠的 条评论
为什么被折叠?



