Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why does this thread block

 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic