My goal is to set up a scheduled job that starts running at startup.
on EJB 3.1, I could do something like:
@Startup
@Stateless
public class SchedulePoller {
@Resource
TimerService timerService;
@PostConstruct
public void defineScheduler() {
timerService.createTimer(60000, 60000, null);
}
@Timeout
public void checkSchedule(Timer timer) {
System.out.println("time: " + new Date());
}
}
Now my problem is that @Startup is not available in EJB 3.0, which is the most updated version supported on WebLogic 11gR1 (10.3.5). This implies that the Bean is not constructed, thus not calling the defineScheduler method.
I have read that a possible solution is to define an HttpServlet, with injected my Bean, override init method and put <load-on-startup> in web.xml file. I cannot use this method because my project is an EJB module and I don't have a web context.
The only other solution I have thought so far is to change the Bean to a @MessageDriven and put a message on the queue after the startup, but this would require extra action at every deploy.
Is there any way to replicate the @Startup annotation? Best option is with a Bean automatically starting at startup, but I can consider also a script to add to StartWebLogic.cmd or any other "automatic" way.
Thank you.
Aucun commentaire:
Enregistrer un commentaire