I am not clear with daemon thread in java,why main method cannot be convert into daemon thread and how can we know that daemon thread is terminated by jvm ?
Asked
Active
Viewed 222 times
-2
-
Imagine if the main thread were a daemon thread; it would start up, there would immediately be no non-daemon threads so the process would be terminated. Doesn't sound very useful, does it? You can emulate the same behaviour with an empty `main()` method if you want to. – Kayaman Dec 23 '15 at 07:24
1 Answers
1
how can we know that daemon thread is terminated by jvm
Wrong. The JVM terminates when all threads running in it are daemon threads. Making main thread a daemon thread would do no good.
Typically, daemon threads are used to do clean-up tasks i.e, the tasks that can be stopped (unlike the core / important part of your app) without affecting the app too much.

TheLostMind
- 35,966
- 12
- 68
- 104