计时quartz任务执行时长
是否有记录 Quartz 执行任务所需时间的标准方法?我也对基于 Spring 的解决方案持开放态度,因为我正在使用两者。
Is there a standard way of logging the time Quartz takes to execute a task? I'm open to Spring based solutions as well, as I'm using both.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
朮生2024-08-17 11:47:11
您可以使用 JobListener
来实现此目的。作业的执行时间甚至由上下文提供。监听器需要添加到使用的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();
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以使用通用计时库,例如 ERMA。它与弹簧结合得非常好。
You can use a general purpose timing library, such as ERMA. It integrates very nicely with spring.