This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why does this thread block Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why does this thread block" Watch "Why does this thread block" New topic
Author

Why does this thread block

Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637

The above method instantiates a annoymous implemntor of Runnable interface and defines a instance iniatlizer that acquires a lock on the annonymous implementer object and invokes wait() and then blocks forever? why does this happen?
And how to make the thread run again and complete the execution to display "I am in run()", without commenting wait()?
Thanks
Deepak


SCJP, SCWCD, SCBCD
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41150
    
  45
and then blocks forever? why does this happen?

It blocks because the wait() call tells it to block. To wake it up another process needs to call notify() on it. But because there is no other code that could do this, it stays blocked and waiting.

I'm assuming you meant ".run()" instead of ".start()", by the way.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why does this thread block
 
Similar Threads
A few questions on wait(), sleep(int) and InterruptedException
Thread question - uCertify 6.0
wait( ) method behind the scene ...
Confuon in Thread Problem
SCJP / strange behaviour when using Thread-Constructor