File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exam LAb Threads Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exam LAb Threads Problem" Watch "Exam LAb Threads Problem" New topic
Author

Exam LAb Threads Problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634


is it necessary to have wait,notify in synchronized block or method


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Yes. wait(), notify() and notifyAll() methods must be called withing synchronized context( synchronized block, synchronized method)..These methods are not in SCJP exam as per other ranchers comments. Serialization is also not in the exam it seems.


OCPJP 6.0-81% | Preparing for OCWCD
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
Rohit Ramachandran
Ranch Hand

Joined: Oct 05, 2010
Posts: 102
wait is thrown and caught. But t.notifyAll() throws an IllegalMonitorStateException.
Trivikram Kamat
Ranch Hand

Joined: Sep 26, 2010
Posts: 155
Rohit Ramachandran wrote:wait is thrown and caught

Actually, wait() is not an exception which can be thrown.
IllegalMonitorStateException is (also) thrown when wait() is called, as method is not synchronized.
But in that case, Ex-B is printed.


OCPJP6
Trivikram Kamat
Ranch Hand

Joined: Sep 26, 2010
Posts: 155
mohitkumar gupta wrote:
is it necessary to have wait,notify in synchronized block or method


Yes, it's necessary.

Wait and Notify provides a means of communication between threads which are synchronized on the same object.
When a Thread calls wait() method in synchronized context, it releases the object lock and waits.
Invoking notify() method from other thread occupying that object lock wakes up the waiting thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exam LAb Threads Problem
 
Similar Threads
Thread interrupt confusion
Thread Problem
Question from examlab on threads
THREAD
Q 28 of examlab practice test 3