如何确保只执行EJB Timer Service的一个线程

时间:2016-02-23 22:01:08

标签: java multithreading jboss ejb-timer

我试图将我的简单Quartz作业转换为JBOSS EAP 6.4中的EJB计时器服务作业。

我有一个问题,我无法找到一个好的答案。我希望每天凌晨1点运行此方法。

这是我的班级。

@Singleton
@Startup
public class JobExecutorService {

    @Schedule(second = "*", minute = "*", hour = "1",persistent = false)
    public void scheduleJobs() throws InterruptedException {
        new ClinicalTrialsDataExtractor().execute();
    }
}

我在控制台中收到这些错误:

16:51:20,002 WARN  [org.jboss.as.ejb3] (EJB default - 3) JBAS014143: A previous execution of timer [clinicalTrials.clinicalTrials.JobExecutorService ed420447-56b0-4d27-9533-f77e8a80ffbb] is still in progress, skipping this overlapping scheduled execution at: Tue Feb 23 16:51:20 EST 2016 as timer state is IN_TIMEOUT
16:51:21,004 WARN  [org.jboss.as.ejb3] (EJB default - 4) JBAS014143: A previous execution of timer [clinicalTrials.clinicalTrials.JobExecutorService ed420447-56b0-4d27-9533-f77e8a80ffbb] is still in progress, skipping this overlapping scheduled execution at: Tue Feb 23 16:51:21 EST 2016 as timer state is IN_TIMEOUT
16:51:22,005 WARN  [org.jboss.as.ejb3] (EJB default - 5) JBAS014143: A previous execution of timer [clinicalTrials.clinicalTrials.JobExecutorService ed420447-56b0-4d27-9533-f77e8a80ffbb] is still in progress, skipping this overlapping scheduled execution at: Tue Feb 23 16:51:22 EST 2016 as timer state is IN_TIMEOUT
16:51:23,004 WARN  [org.jboss.as.ejb3] (EJB default - 6) JBAS014143: A previous execution of timer [clinicalTrials.clinicalTrials.JobExecutorService ed420447-56b0-4d27-9533-f77e8a80ffbb] is still in progress, skipping this overlapping scheduled execution at: Tue Feb 23 16:51:23 EST 2016 as timer state is IN_TIMEOUT
16:51:24,002 WARN  [org.jboss.as.ejb3] (EJB default - 7) JBAS014143: A previous execution of timer [clinicalTrials.clinicalTrials.JobExecutorService ed420447-56b0-4d27-9533-f77e8a80ffbb] is still in progress, skipping this overlapping scheduled execution at: Tue Feb 23 16:51:24 EST 2016 as timer state is IN_TIMEOUT

阻止这些线程尝试旋转的最简单方法是什么?

1 个答案:

答案 0 :(得分:0)

我很惊讶没有人回答这个相对简单的问题。问题归结为我的@Schedule注释中的错误。该方法试图每秒被触发,因此*。正确的方法是:

@Schedule(second = "0", minute = "0", hour = "1",persistent = false)
public void scheduleJobs() throws InterruptedException {
        new ClinicalTrialsDataExtractor().execute();
}