Hi,

I'm using Quartz Scheduler for scheduling regular jobs or for keeping time intensive work units out from the Application's init method.

Please see Task execution. What is the right way to set application to the ThreadContext? Is it fine to do it like this without introducing leaks of any kind? Tasks may repeat forever in a few minutes interval.

Or should I code tasks in a way that does not need application set in thread local?

Thank you in advance.
Vit





Scheduler setup - Application's init() method
=========

JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("application", application); <--- reference to the application

JobDetail job5min = newJob(Job5Min.class).withIdentity("MyIdentity", "group1").setJobData(jobDataMap).build();
Trigger trigger5min = newTrigger().withIdentity("trigger.5min", "group1")
.withSchedule(simpleSchedule().withIntervalInMinutes(5).repeatForever())
            .startNow().build();

scheduler.scheduleJob(job5min, trigger5min);


Task execution
=========


public void execute(JobExecutionContext context) throws JobExecutionException
    {
Application application = (Application)context.getMergedJobDataMap().get("application");
        ThreadContext.setApplication(application);

        ... code ...

        ThreadContext.setApplication(null);
        ThreadContext.detach();
    }



Scheduler stop - Application's onDestroy() method
=========

scheduler.stopScheduler();





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to