aspose file tools*
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
Author

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 www.jiris.com. 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
Thx
Jamal Hasanov
Ranch Hand

Joined: Jan 08, 2002
Posts: 411
I think, its OK - no problem in question...
Jamal Hasanov
www.j-think.com
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(Test.java:6)

Francisco


Francisco<br />SCJP<br />please use the [code][/code] tags when showing code.Click <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" 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: http://aspose.com/file-tools
 
subject: wait( ) notify() Sync