EJB 3タイマーに複数の問題が発生しました。 多くのブログで説明されているように、アノテーションにタイマーを設定するのではなく、プログラム設定を使用します。私は私のログを見ると、私はそれが二回ジョブを開始証明し、ログイン二回「ジョブ開始」を取得し、今EJB3タイマーが複数回実行される
@Singleton
@Startup
public class AutoAssignTask extends AbstractDirectoryMonitor {
@Resource
private TimerService timer;
@Inject
@PropertyResource(name = "timer.hour", resource = "/DL4/app.conf")
private String hour;
@Inject
@PropertyResource(name = "timer.minute", resource = "/DL4/app.conf")
private String minute;
@Inject
@PropertyResource(name = "timer.second", resource = "/DL4/app.conf")
private String second;
@EJB
private AutoAssignService autoAssignService;
@PostConstruct
public void init() {
// initializing with an expression.
this.initSchedule();
}
protected void initSchedule() {
ScheduleExpression exp = new ScheduleExpression();
if (!StringUtils.isEmpty(this.getHour())) {
exp.hour(this.getHour());
}
if (!StringUtils.isEmpty(this.getMinute())) {
exp.minute(this.getMinute());
}
if (!StringUtils.isEmpty(this.getSecond())) {
exp.second(this.getSecond());
}
this.getTimer().createCalendarTimer(exp);
}
@Timeout
public void process() {
// do something
AutoAssignTask.LOG.info("starting job.");
}
のは、私は毎分のためのタイマーを設定しましょう:ここに私のコードです。
何が問題なのですか?
これはEJB 3.1コードであり、3.0ではなく、それに応じてタグが変更されました。 –