【问题标题】:@Schedule equivalent for Guice: execute tasks in @singleton at specified intervalsGuice 的 @Schedule 等效项:以指定的时间间隔在 @singleton 中执行任务
【发布时间】:2011-09-02 14:34:03
【问题描述】:

我正在使用 Google Guice、Guice servlet 和 Jersey。我想找到一种在 JVM 中运行计划作业的简单方法。我找到了以下 EJB 示例,它创建了“带有@Schedule 方法的@Singleton EJB,它以指定的时间间隔在后台执行”。这正是我想做的,但希望看到一种简单的方法来做到这一点,而无需添加 EE 依赖项。

Java mail how to send automatically an email on condition

【问题讨论】:

    标签: jakarta-ee jersey guice guice-servlet


    【解决方案1】:

    您可能会发现 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();
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-29
      • 2018-03-11
      • 2014-07-24
      • 1970-01-01
      • 2014-02-15
      • 1970-01-01
      • 2013-07-08
      相关资源
      最近更新 更多