Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when a quartz job fires, is it a new job class instance?

I am very new to Quartz and I have some doubts about the jobs lifecycle.

Let's suppose I have a single job configured to do some stuff.

The job fires and ends its work. When it fires again is it the same instance (maybe set to sleep and awaken by the scheduler) or is it a new job instance (once the job ends it is killed and when the trigger condition is met again a new job instance is created)?

I ask such question because when I debug my application (spring 3 mvc with quartz support) I see new instances of the job and new threads with SimpleThreadPool$WorkerThreadRun() opened for every time the job is fired so that the SimpleThreadPool$WorkerThreadRun() threads are piled up and never terminated.

I just want to know if this behaviour is allright or I'm bound to fill the memory ;-)

Can anyone give me some explanation? Thanks in advance.

like image 756
MaVVamaldo Avatar asked May 05 '12 14:05

MaVVamaldo


1 Answers

Quartz creates new instance of your job class every time it wants to trigger that job. Suppose you have hundreds of thousands of jobs scheduled to trigger very infrequently - it would be a waste of memory to keep all those jobs in memory.

However if you are using Spring support for Quartz, especially the MethodInvokingJobDetailFactoryBean, Spring will handle the lifecycle of your job (it basically calls designated method of one of your beans). But seems not to be the case in your application.

Of course after the job is done and no other references are pointing to it (which is the normal case) garbage collector will eventually release the memory occupied by the job).

Finally about threads - Quartz creates a fixed pool of worker threads (see org.quartz.threadPool.threadCount configuration option). Every time you run a job Quartz may decide to use a different thread - but it won't create new thread per every trigger.

like image 199
Tomasz Nurkiewicz Avatar answered Sep 28 '22 08:09

Tomasz Nurkiewicz