File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock exam question

 
santhoshkumar samala
Ranch Hand
Posts: 156
Eclipse IDE Hibernate Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Leonardo Rafaeli
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
runtime exception because the wait() is not on a synchronized block
 
Naresh Gunda
Ranch Hand
Posts: 163
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • 0
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marcus,

I have not seen any explanation there, may be because I am accessing as guest
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic