【发布时间】:2014-06-05 12:23:03
【问题描述】:
目前我的应用程序正在使用多个 EJB 计时器。但是,客户有一个新要求,每个时间表必须有“n”个不同的 ScheduleExpression。例如,它必须针对不同的时区运行,但运行完全相同的代码。我试图将同一个无状态 EJB 与另一个 ScheduleExpression 相关联,但只有第一个表达式运行。我猜这是因为它是 @Stateless EJB 的同一个实例。
如何复制这些 EJB? 提示
我的启动计划的代码:
Calendar cal = Calendar.getInstance();
String hour = ("*".equals(calendarSchedule.getHour()) ? "0"
: calendarSchedule.getHour());
cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hour));
String minute = ("*".equals(calendarSchedule.getMinute()) ? "0"
: calendarSchedule.getMinute());
cal.set(Calendar.MINUTE, Integer.parseInt(minute));
String dayOfWeek = ("*".equals(calendarSchedule.getDayOfWeek()) ? "0"
: calendarSchedule.getDayOfWeek());
cal.set(Calendar.DAY_OF_WEEK, Integer.parseInt(dayOfWeek));
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm");
LOGGER.debug("schedule " + name + " for: "
+ sdf.format(cal.getTime()));
}
TimerConfig timerConfig = new TimerConfig();
timerConfig.setInfo(name);
timerConfig.setPersistent(false);
timerService
.createCalendarTimer(this.calendarSchedule, timerConfig);
setStarted(true);
LOGGER.info("Schedule " + this.name + " was started.");
应用程序在 WebSphere 8.5 上运行。计划不固定。我使用@Singleton 和@Startup EJB 来读取带有ScheduleExpression 的表。现在表格可以有两个条目用于同一个时间表。
【问题讨论】:
标签: jakarta-ee timer ejb-3.1