• 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

Mock exam question

 
Ranch Hand
Posts: 156
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Answer given is 1, when I compile and run Iam getting runtime exception.. but I have two queries about this question

1)In k&b book it is mentioned that wait,notify and notify all must be called from synchronized block, so why I am not getting compile error here?

2)can we call start() method like above?
[ December 19, 2005: Message edited by: santoshkumar samala ]
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
runtime exception because the wait() is not on a synchronized block
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In k&b book it is mentioned that wait,notify and notify all must be called from synchronized block,

Yes. Otherwise Runtime Exception. No compilation error.

java.lang.IllegalMonitorStateException: current thread not owner
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question (originally) comes from one of my mock exams, and it includes the following explanation with the answer.

Compilation but runtime error.

At runtime an error indicating java.lang.IllegalMonitorStateException because the wait call is not within synchronized code. Changing the signature of payBill to public synchronized void payBilll would remove the runtime error, causing the program to run and then pause with no output.

Does the explanation look correct, and if so is there something I can do to change the answer to make the explanation more clear?
[ December 19, 2005: Message edited by: Marcus Green ]
 
santhoshkumar samala
Ranch Hand
Posts: 156
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Marcus,

I have not seen any explanation there, may be because I am accessing as guest
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic