计划任务执行两次 [英] Scheduled task executed twice
本文介绍了计划任务执行两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有两个 @Schedules
的无状态会话bean:
I have a Stateless session bean with two @Schedules
:
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
@Stateless
@Lock(LockType.WRITE)
@AccessTimeout(value = 0)
public class ScheduledTask {
@EJB
private SomeClass sClass;
@Schedules({
@Schedule(hour = "*", minute = "*/10",
info = "Automatic timer to send")})
public void send() {
sClass.doWork(true);
}
@Schedules({
@Schedule(hour = "*", minute = "*/35",
info = "Automatic timer to receive")})
public void receive() {
sClass.doWork(false);
}
}
我的问题是任务执行了两次。我已阅读 topic ,但我没有找到解决方案。
My problem is that the tasks are executed twice. I have read topic but I have not found a solution.
我在控制台中有相同的输出(例如(EJB default-1)和(EJB default-2)):
I have in console the same output (like (EJB default - 1) and (EJB default - 2)):
INFO [GENERAL_LOGGER] (EJB default - 2) resultForSend.size() = 500
INFO [GENERAL_LOGGER] (EJB default - 1) resultForSend.size() = 500
推荐答案
解决方案是从WAR模块中删除EJB类。我在EAR中的两个单独的模块(EJB和WAR)中具有相同的类,因此 Schedules
被注册了两次。包装过程中的一个愚蠢错误导致重复执行。
The solution was to remove the EJB class from a WAR module. I had the same class in two separate modules - the EJB and WAR - inside EAR and hence the Schedules
were registered twice. A silly mistake during packaging that resulted in the double execution.
这篇关于计划任务执行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文