• 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:

a little clarification again about wait() notify()

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
reply
    Bookmark Topic Watch Topic
  • New Topic