Vinay Kumar T M wrote:
I am not able to understand why the current thread goes into deadlock ?. The current thread name is main. To my knowledge, when join on current thread(which is the same main) is issued, main waits for main to complete ? so, it goes in deadlock ?. The execution never completes. why wouldn't the JVM cant figure out that it is hogging itself ?
Well, the main thread can't complete until it accomplishes everything. And one of the tasks is waiting for the itself to complete first, before it can complete.
As for the JVM detecting this, what would be the point? The JVM is there to do as the program asks, and arguably not really to protect the program from doing something silly. And even if it was, it would be a ridiculous hard thing for the JVM to do right? as a program can do an infinite number of silly things.
Vinay Kumar T M wrote:
I tried to make it a Daemon, but I get illegalThreadStateException. Is that becuase the main thread is already in RUNNING status and it is too late to be changed to Daemon ?.
Correct. You can't set the daemon state once the thread has started.
Henry