views:

30

answers:

2

I have setup quartz.net to run a scheduled job. It is amazing when I look at the thread ids. They just get repeated in 10-thread interval.

I mean for instance if the first thread that gets to execute my job has id 101 then the eleventh thread (that runs the same job at the eleventh interval) has the same id 101!

It seems that quartz.net is using a pool of 10 threads but more amazing is why the threads have the same id? Shouldn't they get new thread id each time they are created?

+1  A: 

Haven't you answered your own question? I know little about quartz, but if it uses a thread pool then, yes, it's going to reuse threads. The high cost of spinning up threads is one of the problems solved by a thread pool, so this cost is avoided by reusing existing threads (i.e. a new thread is not spun-up every time a work request is processed)

spender
are you saying that the threads are not actually recycled and they are reused in quartz.net ? how about the thread local storage? is it reset/cleared each time ? can we force it to reset ?
kaptan
Ah. In my mind recycled==reused, so perhaps this is causing confusion. As for your second point: You provide a method to be scheduled. Method executes. Upon completion, locals fall out of scope. Job done. Thread goes to sleep, is awoken when more work arrives. http://en.wikipedia.org/wiki/Thread_pool_pattern
spender
+1  A: 

This is because the default scheduler in Quartz.NET is the DirectSchedulerFactory, which uses an internal ThreadPool implementation (SimpleThreadPool).

This will setup a fixed number of threads, and reuse the same threads for jobs. This prevents you from getting new thread IDs per job, since threads != jobs.

Reed Copsey