【问题标题】:Timing quartz task execution duration计时石英任务执行持续时间
【发布时间】:2009-11-10 16:27:28
【问题描述】:

是否有记录 Quartz 执行任务所需时间的标准方法?我也对基于 Spring 的解决方案持开放态度,因为我同时使用这两种解决方案。

【问题讨论】:

    标签: java spring profiling quartz-scheduler


    【解决方案1】:

    您可以使用通用时序库,例如ERMA。它与spring的结合非常好。

    【讨论】:

      【解决方案2】:

      您可以实现JobListener 并将其作为global job listener 添加到调度程序中。

      这将为您提供一些关于何时执行作业以及何时完成执行的钩子。您应该能够使用这些钩子来记录作业的开始和结束时间,然后记录运行时间。

      【讨论】:

      • 链接已过时(失效)。
      【解决方案3】:

      您可以为此使用JobListener。作业的执行时间甚至由上下文提供。 Listener 需要添加到使用过的Scheduler:

      public class GlobalJobRuntimeListener implements JobListener {
          //... other methods to overwrite 
      
          @Override
          public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
              System.out.println("Job with key " + context.getJobDetail().getKey().toString()
                      + " finished in " + context.getJobRunTime() + " ms.");
          }
      }
      

      -

      Scheduler scheduler = schedulerFactory.getScheduler();
      scheduler.getListenerManager().addJobListener(new GlobalJobRuntimeListener());
      scheduler.start();
      

      【讨论】:

        猜你喜欢
        • 2012-06-11
        • 1970-01-01
        • 2019-04-08
        • 1970-01-01
        • 1970-01-01
        • 2012-06-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多