【问题标题】:Execution of ScheduledExecutorService on multiple servers在多台服务器上执行 ScheduledExecutorService
【发布时间】:2019-07-03 09:01:08
【问题描述】:
我的耳朵将作为后端耳朵部署在多台服务器上。在那个耳朵里,我需要添加 ScheduledExecutorService 以在特定时间从数据库中获取一些记录并处理它们。但是我只需要处理一次,而不是在将要部署耳朵的所有服务器上。仅在 java8 上使用 ScheduledExecutorService 可以实现吗?还是我需要使用另一个可以实现此目的的库?
【问题讨论】:
标签:
java
websphere
scheduledexecutorservice
【解决方案1】:
java.util.concurrent.ScheduledExecutorService是Java SE定义的接口。它没有指定任何实现要求,以建立对应用程序服务器的认识或协调。即使是由 Java EE 定义的javax.enterprise.concurrent.ManagedScheduledExecutorService 接口,也没有任何要求感知/协调跨不同应用程序服务器的调度,因此当前由 WebSphere Application Server 提供的实现目前不提供这种能力。但是,Java EE 中有另一种技术确实提供了这种能力:持久 EJB 计时器。请参阅 linked knowledge center article 作为 WebSphere Application Server 传统的起点。如果您使用的是 WebSphere Application Server Liberty,则该功能当前受到更多限制,并且如果分配给运行它的服务器出现故障,则无法跨服务器执行任务以进行故障转移。目前有针对 Liberty 的增强请求。