This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes wait( ) notify() Sync Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "wait( ) notify() Sync" Watch "wait( ) notify() Sync" New topic

wait( ) notify() Sync

Deepali Pate
Ranch Hand

Joined: Mar 20, 2002
Posts: 114
Question mockexam-scjp2-01-12:

Is the following statement correct?
(Select one correct answer)
I guess not many have been to Its good. Try the mock exams there.
One of the ? there is
"The notify() and notifyAll() methods can only be called within a synchronized code, otherwise there will be compile error."
A: True
B: False
Ans is false but explaation given says
It is not a compile time error, instead it will be a runtime time exception as IllegalMonitorStateException
Is the ? worded rightly. Should it not include wait().
Plz clarify
Jamal Hasanov
Ranch Hand

Joined: Jan 08, 2002
Posts: 411
I think, its OK - no problem in question...
Jamal Hasanov
Francisco A Guimaraes
Ranch Hand

Joined: Mar 20, 2002
Posts: 182
try it for yourself:

it compiles and gives this output when you run it:

Exception in thread "main" java.lang.IllegalMonitorStateException: current thread not owner
at java.lang.Object.notify(Native Method)
at Test.main(


Francisco<br />SCJP<br />please use the [code][/code] tags when showing code.Click <a href="" target="_blank" rel="nofollow">here</a> to see an example.
Deepali Pate
Ranch Hand

Joined: Mar 20, 2002
Posts: 114
Thnx but can u use only notify() in a class without calling wait()? Would it mean anything if we did so?
I agree. Here's the link:
subject: wait( ) notify() Sync