Perfect, thank you.
Vit

On 07/10/2017 06:05 AM, Martin Grigorov wrote:
Hi,

On Sat, Jul 8, 2017 at 5:33 PM, Vit Rozkovec <vit.rozko...@gmail.com> wrote:

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

I'd pass just the name (Application#getName()).


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.getMerged
JobDataMap().get("application");

And then use it to lookup the application instance: Application app =
Application.get(appName);


         ThreadContext.setApplication(application);

         ... code ...

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

This logic should be in try/finally, i.e. the cleanup methods should be in
finally.


     }



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




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

Reply via email to