0

Generally Daemon threads are the low priority threads and provide services to user threads and dies when all user threads completes their executions. But Any class extending thread(daemon thread by setting serDaemon(true)) we can able to set their priority as well. Here is my question is how JVM ignores the priority during Scheduling of daemon thread .

  • 3
    Whether the thread is a daemon or not has no effect on thread priority; it only means that the JVM will exit when only daemon threads are running. They could all be the highest priority. – Erwin Bolwidt Oct 10 '19 at 05:44
  • 2
    Also, Thread priorities are not supported on many platforms. On these platforms, all threads have the same effective priority regardless of what you set with `Thread.setPriority`. See [Do Linux JVMs actually implement Thread priorities?](https://stackoverflow.com/questions/1662185/do-linux-jvms-actually-implement-thread-priorities) – Erwin Bolwidt Oct 10 '19 at 05:49
  • 1
    @ErwinBolwidt are you sure that is still an issue these days? I can run a program with a low priority thread for every core that does heavvy computations without the system slowing down – Ferrybig Oct 10 '19 at 05:59
  • @Ferrybig It's easy to check - here's [the source for JDK12](http://hg.openjdk.java.net/jdk/jdk12/file/06222165c35f/src/hotspot/os/linux/os_linux.cpp) - the method `set_native_priority` still has the exact same implementation. Doesn't do anything for non-root users, will do something imperfect when Java is ran as root and the `-XX:ThreadPriorityPolicy` is provided to the JVM (I **don't** advise to run Java as root) – Erwin Bolwidt Oct 10 '19 at 22:34

0 Answers0