我正在使用 Google Guice、Guice servlet 和 Jersey。我想找到一种在 JVM 中运行计划作业的简单方法。我发现了以下 EJB 示例,它创建了“带有@Schedule 方法的@Singleton EJB,它以指定的时间间隔在后台执行”。这正是我想做的,但希望看到一种简单的方法来做到这一点,而无需添加 EE 依赖项。
问问题
3166 次
1 回答
3
您可能会发现 Guice 的 Quartz 集成在这里满足您的要求 -
https://github.com/99soft/guartz
这是语法示例
@javax.inject.Singleton
@org.nnsoft.guice.guartz.Scheduled(jobName = "test", cronExpression = "0/2 * * * * ?")
public class com.acme.MyJobImpl implements org.quartz.Job {
@javax.inject.Inject
private MyCustomService service;
public void execute(JobExecutionContext context) throws JobExecutionException {
service.customOperation();
}
}
于 2011-09-05T11:54:05.567 回答