如何找到线程在 java 中运行的 Quartz 作业? [英] How can I find which Quartz job a thread is running in java?

查看:47
本文介绍了如何找到线程在 java 中运行的 Quartz 作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用鉴别器来登录不同的文件.基于线程名称.它通常会给出很好的结果,除了石英作业都是在文件中记录的名称如下:

I am using a discriminator for logging in different file. Based on the thread name. It usually give good result, except for the quartz job that are all logger in file with name like :

org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-1.log

org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-1.log

我想要一个文件,它是石英作业的名称(基于它),以便能够快速找到包含作业日志的文件.有没有办法询问quartz当前线程是否与作业相关联?

I would like to have a file that is the name of the quartz job (on something base on it) to be able to quickly find which file contains the logs for a job. Is there a way ask quartz if the current thread is associated with a job?

谢谢

推荐答案

最后我用slf4j MDC手动指示解决

Finally, I resolve it by manually indicating with slf4j MDC

在任务开始时,我做

try {
    MDC.put(MDC_KEY, getTaskName());

最后

    }
    finally {
        MDC.remove(MDC_KEY);
    }

所以我只需要检查 MDC 中的密钥即可知道我是否在任务中.

So I just need to check the key in MDC to know if I am inside a task.

这篇关于如何找到线程在 java 中运行的 Quartz 作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆