InterviewSolution
| 1. |
What Is Difference Between User Thread And Daemon Thread? |
|
Answer» By DEFAULT a thread created in a JAVA program is always a user thread however we can make it daemon by calling setDaemon(true) method, if NEEDED. A daemon thread runs in the background and doesn’t prevent JVM from terminating. As soon as all user thread finishes execution, Java program or JVM terminates itself, JVM doesn’t wait for daemon thread to finish their execution. As soon as last non daemon thread finished, JVM terminates no matter how many Daemon thread exists or RUNNING INSIDE JVM. By default a thread created in a Java program is always a user thread however we can make it daemon by calling setDaemon(true) method, if needed. A daemon thread runs in the background and doesn’t prevent JVM from terminating. As soon as all user thread finishes execution, Java program or JVM terminates itself, JVM doesn’t wait for daemon thread to finish their execution. As soon as last non daemon thread finished, JVM terminates no matter how many Daemon thread exists or running inside JVM. |
|