File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread issue

 
Aurelian Dobre
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Why the following code doesn't block in the wait() method forever?

 
Henry Wong
author
Marshal
Pie
Posts: 20831
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aurelian Dobre wrote:Hi,

Why the following code doesn't block in the wait() method forever?




This issue seems to come up often -- and the quick answer is... The implementation of one of the components of the threading system (in this case, to support the join() method call), uses the wait/notify mechanism. And for some reason, the designer chose to use the thread object as the notification object. This is purely an implementation detail, and hence, may change in the future.

Regardless, don't perform wait() on the thread object, some part of the threading library is already doing that.

Henry

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic