开发者

Timing quartz task execution duration

Is there a standard way of logging the time Qu开发者_开发百科artz takes to execute a task? I'm open to Spring based solutions as well, as I'm using both.


You can use a general purpose timing library, such as ERMA. It integrates very nicely with spring.


You could implement a JobListener and add it as a global job listener to the scheduler.

This will give you some hooks on when a job is about to be executed and when it has finished executing. You should be able to do something with these hooks to record the start and end times of the jobs, and then log the run time.


You can use a JobListener for that. The execution time of a job is even provided by the context. The Listener need to be added to the used 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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜