我創建了一個包含EJB的測試應用程序,該應用程序應該每秒打印一次當前的Timestamp。現在,在我的wild dep上部署Web應用程序後,我每秒鐘都會收到5條日誌消息...看起來像運行多個調度程序,這將觸發輸出...Wildfly Scheduled EJB-多次執行
您有任何想法,要解決這個問題?如果我只用註釋的@Schedule梅索德,它打印每一秒的結果,而是由定時編程,使問題:
@Singleton
@Startup
public class Scheduler {
@Resource
TimerService timerService;
@Inject
Logger logger;
@Timeout
public void doStuff() {
logger.info("Programmatic Scheduler: " + System.currentTimeMillis());
}
@PostConstruct
public void startScheduler() {
TimerConfig timerConfig = new TimerConfig();
timerConfig.setPersistent(false);
ScheduleExpression expression = new ScheduleExpression();
expression.second("*/1").minute("*").hour("*");
timerService.createCalendarTimer(expression, timerConfig);
}
}
...和here's您參見輸出每秒打印多份:
16:26:46,574 INFO [de.hays.liferay.schedulerprogrammatically.Scheduler] (EJB default - 10) Programmatic Scheduler: 143455120657
16:26:46,849 INFO [de.hays.liferay.schedulerprogrammatically.Scheduler] (EJB default - 8) Programmatic Scheduler: 1434551206849
16:26:46,869 INFO [de.hays.liferay.schedulerprogrammatically.Scheduler] (EJB default - 7) Programmatic Scheduler: 1434551206869
16:26:46,890 INFO [de.hays.liferay.schedulerprogrammatically.Scheduler] (EJB default - 4) Programmatic Scheduler: 1434551206890
16:26:47,083 INFO [de.hays.liferay.schedulerprogrammatically.Scheduler] (EJB default - 3) Programmatic Scheduler: 1434551207083
16:26:47,145 INFO [de.hays.liferay.schedulerprogrammatically.Scheduler] (EJB default - 1) Programmatic Scheduler: 1434551207145
16:26:47,185 INFO [de.hays.liferay.schedulerprogrammatically.Scheduler] (EJB default - 9) Programmatic Scheduler: 1434551207185
16:26:47,246 INFO [de.hays.liferay.schedulerprogrammatically.Scheduler] (EJB default - 6) Programmatic Scheduler: 1434551207246
16:26:47,274 INFO [de.hays.liferay.schedulerprogrammatically.Scheduler] (EJB default - 2) Programmatic Scheduler: 1434551207274
16:26:47,489 INFO [de.hays.liferay.schedulerprogrammatically.Scheduler] (EJB default - 5) Programmatic Scheduler: 1434551207489
是的,我用的是使用javax。 ejb.Singleton – goblingift