• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a little clarification again about wait() notify()

 
saima kanwal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question about my previous post regarding wait() notify()

I understood the explanation but for the exam point of view , what are we going to do if such type of question comes in paper. I mean if a thread does not do notify and the other thread calls wait on that thread object ( as i have posted earlier), so are we going to acknowledge the implementation detail fact about Thread ( according to which it calls notifyall implicitly once it completes). If we acknowledge this fact then the behavior of such a the code if asked in exam would not be a thread waiting forever and git simply gives the output. On the other hand if we do not acknowledge it then then we should say that the thread will wait for ever as there is no notify. Please clarify what to do in exam ?? I am confused because Henry wrote earlier that:

This is an implementation detail, and can't be dependent to behave this way with all JVMs.

Henry


So what to do in exam??
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
His answer was pretty clear. It is not part of a spec so other threads will wait forever. You cannot rely on a specific JVM / OS to give an answer to that question
 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Deepak said, that the answer would be that the wait call will wait forever in the second code (from exam point of view). But the specific examples that you gave in that other topic, both the codes might keep waiting forever.

In this code, the run method might get the lock over ThreadB object before the main method, so the call to wait in the main method might never return. Same is with the second code. So for the first code, the output is unpredictable (output can be 45 or the program could wait forever) and for the second code, the output is that the program will wait forever...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic