4

I understand the difference between a daemon thread and a regular thread. By calling setDaemon(true), the thread will be marked such that it will not keep the JVM alive. The JVM will automatically shut down when there are no more non-daemon threads running. When you start up the JVM, only the main thread is a non-daemon thread.

I also understand that the priority of a thread can be set independently of this. By calling setPriority(Thread.MAX_PRIORITY), the thread will be set to have the maximum scheduling priority allowed by its thread group. I feel like I have a good grasp on these concepts.

My question is - is there anything inherent in the daemon thread that would reduce its priority? or is it merely a flag saying "you don't have to wait for me to shut down the JVM"?

I'm working with a thread in a shared library that cannot be shutdown through the API. I have asked for this thread to be flagged as a daemon thread, but the owner is concerned that this will reduce its priority in the scheduler. It seems to me that since the priority is managed separately from the daemon thread designation, that they should be orthogonal. I'm having a hard time finding documentation of this, however.

Erick Robertson
  • 32,125
  • 13
  • 69
  • 98
  • 1
    Thread scheduling is ultimately the responsibility of the OS. Java Thread priorities are implemented differently for different OSs, and under some common circumstances, Java thread priority has no practical effect at all. Although there is no documented association between threads' daemon status and scheduling, in principle, a given implementation could indeed give preference to non-daemon threads. As with any performance question, your best alternative is to *test*. – John Bollinger Sep 17 '15 at 19:57
  • The fact that there is no documentation is entirely in your favour. You won't find documentation of something that doesnt exist. It is up to the 'thread owner' to justify his concerns. – user207421 Sep 17 '15 at 21:43

0 Answers0