• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Thread goes to Deadlock

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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 ?

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 ?.

 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Vinay Kumar T M
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the quick answer. Sorry, I used the term JVM. I meant to say Compiler.

Wouldn't compiler detecting this doesnt make sense as well ?

Thanks,
Vinay
 
Henry Wong
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vinay Kumar T M wrote:Thanks for the quick answer. Sorry, I used the term JVM. I meant to say Compiler.

Wouldn't compiler detecting this doesnt make sense as well ?



Same response. A program can do an infinite number of silly things. It is just silly for the compiler to try to detect / fix it all as well.  And in my opinion, it would be very difficult to compile a class, based on the (assumed) behavior of another class. And what happens if a framework wants to interpose (replace) the Thread class with their own?

Henry
reply
    Bookmark Topic Watch Topic
  • New Topic