gpt4 book ai didi

java - Eclipse : ScheduledExecutorService. scheduleWithFixedDelay 不会在发布时删除

转载 作者:行者123 更新时间:2023-11-29 05:48:21 29 4
gpt4 key购买 nike

我遇到了奇怪的问题。

我有一个 ScheduledExecutorService.scheduleWithFixedDelay 当我点击发布/停止重启服务器时它不会“停止”。

当我重新发布时,将有 2 个服务运行,相同服务运行的数量取决于我点击发布的次数。

这不会在我停止并启动服务器后消失。

我必须关闭并打开 eclipse 才能停止它,我注意到只有在我编辑初始化服务的类后才会发生这种情况。

我无法粘贴代码,但非常简单..只是一个单例并提供服务

private final ScheduledExecutorService scheduler = 
Executors.newScheduledThreadPool(1);

scheduler.scheduleAtFixedRate(new Runnable() {
public void run() { system.out("hello" }
}, 60 * 60, SECONDS);

我似乎无法找出问题所在,请有人帮助我。

最佳答案

您应该在取消部署应用程序时关闭调度程序。更简单的方法是声明一个实现 ServletContextListener , 并在 contextDestroyed() 方法中关闭 schedler。

关于java - Eclipse : ScheduledExecutorService. scheduleWithFixedDelay 不会在发布时删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14976665/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com