Scheduled task executed twice

三世轮回 提交于 2020-01-05 22:22:13

问题


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);
    }
}

My problem is that the tasks are executed twice. I have read topic but I have not found a solution.

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

回答1:


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.



来源:https://stackoverflow.com/questions/20880145/scheduled-task-executed-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!