java daemon threads

前端 未结 4 1575
春和景丽
春和景丽 2021-01-22 06:45

Hi all, will daemon thread stop working when the enclosing it thread will finish? Or daemon thread will stop when the \"main\" thread will finish?

I tested this example

4条回答
  •  有刺的猬
    2021-01-22 07:12

    will daemon thread stop working when the enclosing it thread will finish?

    There's no such concept as an "enclosing thread" in Java. There are thread groups but they're rarely used.

    Daemon threads are simply threads which don't stop the JVM from terminating. When there aren't any non-daemon threads left, the JVM will terminate. If there are still some non-daemon threads executing, the JVM will keep going, including any daemon threads - whether or not the threads that started those daemon threads have finished.

提交回复
热议问题