Weblogic SingletonService接口实现。两个托管服务器上的线程都是 运行

Weblogic SingletonService interface implementation. Thread is running on both managed server

我实现了位于 weblogic API 内部的 SingletonService 接口。此接口确保实现此接口的 class 仅在一台托管服务器上 运行。在我的例子中,我在 SingletonService 实现 class 的 activate() 方法中有两个线程。 singletonService 已迁移,但线程 运行ning 与该服务器上的一样,它使我的数据库中出现重复条目​​。

当我在 weblogic 上终止并重新启动时,直到一段时间线程 运行 在服务器上和一段时间 运行 在一台服务器上。

解决这个问题真的很简单。我开始知道如何停止线程。 当 SingletonService 被停用时,我使用相同的逻辑来停止执行。 在 deactivate() 中,我们添加了停止线程的逻辑。我们添加了简单的标志,这将有助于中断线程的执行。

sample code

public void deactivate(){
 // take reference of thread and break the execution of thread 
 // call thread.interrupt();
} 

这是我用来解决问题的简单技巧。