开发者

Why does Quartz.NET create threads with the same thread id?

开发者 https://www.devze.com 2023-01-05 19:18 出处:网络
I have set up 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 have set up 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 do the threads have the same ID? Shouldn't they get new thread ID each time they are created?


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.


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)

0

精彩评论

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