Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wait( ) notify() Sync

 
Deepali Pate
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think, its OK - no problem in question...
Jamal Hasanov
www.j-think.com
 
Francisco A Guimaraes
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Deepali Pate
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnx but can u use only notify() in a class without calling wait()? Would it mean anything if we did so?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic