查找当前正在执行 Quartz Job 的线程!

发布于 2024-11-09 23:22:17 字数 1376 浏览 3 评论 0 原文

我正在寻找解决方案来获取当前执行石英作业的线程名称。在我的应用程序中,quartz 是使用属性配置的,作业触发器是数据库驱动的。

在这里,我正在实例化石英并启动它。

StdSchedulerFactory factory = new StdSchedulerFactory(configFile);
Scheduler scheduler = factory.getScheduler();
 scheduler.addGlobalJobListener(new QuartzJobListener());
 scheduler.addGlobalTriggerListener(new QuartzTriggerListener());
scheduler.start();

能够获取石英作业和触发器详细信息如下,

try{
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
List<JobExecutionContext> jobList = scheduler.getCurrentlyExecutingJobs();
for(JobExecutionContext jobExecutionContext : jobList){
    // JOB Details 
    JobDetail jobDetail = jobExecutionContext.getJobDetail();
    String strJobName = jobDetail.getName();
    String strDescription = jobDetail.getDescription();

    // Trigger Details
    Trigger trigger = jobExecutionContext.getTrigger();
    String strTriggerName = trigger.getName();
    String strFireInstanceId = trigger.getFireInstanceId();
    int state = scheduler.getTriggerState(trigger.getName(),trigger.getGroup());
    }
}catch(Exception e){
    e.printStackTrace();
}

我的问题是 - 如何获取正在执行当前作业的线程名称?

这里是 问题解决相同的问题,但截至目前尚未得到任何解决方案回复现在。

I am looking for solution to get the the thread name currently executing the quartz job. In my application, quartz is configured using properties and jobs triggers are DB driven.

Here i am instantiating the quartz and starting it.

StdSchedulerFactory factory = new StdSchedulerFactory(configFile);
Scheduler scheduler = factory.getScheduler();
 scheduler.addGlobalJobListener(new QuartzJobListener());
 scheduler.addGlobalTriggerListener(new QuartzTriggerListener());
scheduler.start();

Able to get the quartz JOB and TRIGGER details as follows,

try{
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
List<JobExecutionContext> jobList = scheduler.getCurrentlyExecutingJobs();
for(JobExecutionContext jobExecutionContext : jobList){
    // JOB Details 
    JobDetail jobDetail = jobExecutionContext.getJobDetail();
    String strJobName = jobDetail.getName();
    String strDescription = jobDetail.getDescription();

    // Trigger Details
    Trigger trigger = jobExecutionContext.getTrigger();
    String strTriggerName = trigger.getName();
    String strFireInstanceId = trigger.getFireInstanceId();
    int state = scheduler.getTriggerState(trigger.getName(),trigger.getGroup());
    }
}catch(Exception e){
    e.printStackTrace();
}

My question is - How can i get the thread name which is executing the current job?

Here is Question addressing the same issue but havent got any solution reply as of now.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹏雨一样淡蓝的深情 2024-11-16 23:22:17

您可以向 Job 类添加一个

private Thread thead;

变量,并在 execute() 方法中设置

thread = Thread.currentThread();

You could add a

private Thread thead;

variable to your Job class and in the execute() method, set

thread = Thread.currentThread();
爱本泡沫多脆弱 2024-11-16 23:22:17

如果只是关于调试和跟踪,请在执行器内使用一些智能日志记录,并且不要弄乱线程(您不想去那里)。

我不确定 Quartz 通过他们的 API 向您提供此信息。但是,您可以配置 Quartz 以与您的线程池一起使用。然后执行器线程信息会更容易。您可以使用 CommonJ 来实现此目的。

祝你好运!

If it is only about debugging and tracing use some smart logging inside your executor and do not mess with the threads (you don't want to go there).

I am not sure Quartz gives this info to you via their API. However, you can configure Quartz to work with your thread pool.Then getting the executor thread info will be much easier. You can use CommonJ for this purpose.

Good Luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文