@Schedule注释每隔几分钟(或几秒钟)运行一次
我想尝试通过以下方式使用@Schedule注释:
public class MyTestServlet extends HttpServlet {
private static JcanLogger LOG = JcanLoggerFactory.getLogger(ServiceTestServlet.class);
@EJB CronService cronService;
public void service(HttpServletRequest req, HttpServletResponse resp) throws .... {
....
cronService.iLive();
}
---
@Local // because the ejb is in a servlet (there is no other jvm)
public interface CronService {
public void iLive();
public void runsEveryMinute();
}
---
@Singleton
public class CronServiceBean implements CronService {
private static final JcanLogger LOG = JcanLoggerFactory.getLogger(CronServiceBean.class);
@Schedule(minute="*")
public void runsEveryMinute() {
LOG.info(" runs EveryMinute ");
}
public void iLive() {
LOG.info("iLive");
}
---
LOG
...
CronServiceBean:34 ] iLive
根据日志,CronService 可以正常运行,但计划任务“runsEveryMinute”不起作用。
它应该如何使用 EJB 调度任务工作?