• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

wait( ) notify() Sync

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think, its OK - no problem in question...
Jamal Hasanov
www.j-think.com
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic