【发布时间】:2021-11-11 14:24:11
【问题描述】:
在我的 Java Web 应用程序中,我使用 ScheduledThreadPoolExecutor 定期检查数据库连接状态。
final ScheduledExecutorService executor = Executors.newScheduledThreadPool(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);
但是,当我从 Web 应用程序注销并关闭浏览器窗口时,我(从日志中)看到它仍在检查连接状态。
有没有办法在关闭 Web 应用程序时终止这个执行器/线程?
【问题讨论】:
标签: java jsp web threadpool java-threads