【发布时间】:2021-11-18 04:40:48
【问题描述】:
在我的 Java Web 应用程序中,我使用 ScheduledThreadPoolExecutor 定期检查数据库连接状态。这适用于每个经过身份验证的用户(每个身份验证)。
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(0);
Runnable task = new Runnable() {
public void run() {
//check the status of the database connection, and log the result
}
};
executor.scheduleWithFixedDelay(task, 0, 10, TimeUnit.MINUTES);
但是,当 corePoolSize = 0 时,ScheduledThreadPoolExecutor 会消耗 100% CPU。设置 corePoolSize = 1,可以解决问题。
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
在生产中,我们将拥有数百名用户。 我的问题是,在这种情况下,corePoolSize 的理想值是多少?
【问题讨论】:
标签: java linux tomcat threadpool threadpoolexecutor