开发者

Find thread currently executing the Quartz Job!

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 = jo开发者_运维问答bExecutionContext.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.


You could add a

private Thread thead;

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

thread = Thread.currentThread();


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!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜