aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Threads and Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads Threads and Threads" Watch "Threads Threads and Threads" New topic
Author

Threads Threads and Threads

Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Please do clarify some of the ambiguities after reading K&B

1) When we notify , do objects waiting on Object lock are eligible for that notification ??

2) Same as above but for notifyAll()

3) Is there any way of intimating those objects which are waiting for lock.

4) Can we call notify or notifyAll() from a non-synchronized method but which is being called from Sunchronized method.

5) What does Synchronized context means, is it include non-synchronized method called from synchronized context.

6) Most important one:- Is this wait, notify and notifyAll() are on SCJP 6 syllabus anymore.

Thanks !!!


SCJP 6.0 96%

(Connecting the Dots ....)
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9317
    
  17

1) When we notify , do objects waiting on Object lock are eligible for that notification ??

Threads gets locks and waits not objects. What is it that you are trying to say here??
4) Can we call notify or notifyAll() from a non-synchronized method but which is being called from Sunchronized method.

This is easy to try out yourself isn't it??

5)Basically once a method occupies a lock on an object, you can call notify, notifyAll and wait on that object in any method as long as that thread has a lock on the object. Try this program, this will solve both 4 and 5th questions

6) I think Bert mentioned its not on the objectives anymore but one rancher said that they faced a question in the exam from this topic. There have been irregularities in the past in the exam, many people get questions from topics which are not in the exam. So IMO its better if you study this topic if you have time...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
@Ankit : Thanks a lot dear !!!

What i meant by query 1 is as follows :-

1)When we notify , do "threads of execution" waiting on that Object lock are eligible for that notification ??

I means suppose , there are certain threads which were not executed and blocked since some other thread has locked an object.
Moreover there are also certain threads which do wait on that object . So there are like two Queues
Queue1:- threads waiting for object notification
Queue2 :- threads waiting for release on the object lock.

I am concerned about Queue2 ???

Thanks !!!
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9317
    
  17

Well the notify call will only wake 1 thread which called wait on the same object. Threads who are blocked because a different thread has the lock on that object don't need to be notified, only threads who call wait need to be notified. After the lock is released by one thread, any blocked threads can acquire the lock. Any threads who called wait on that object and were not notified, won't be able to grab the lock and continue execution...
Raza Rasool
Greenhorn

Joined: May 31, 2010
Posts: 4
Hi Sahil,

The Best thing is that this topic is no more in the SCJP Exam, please consult the Oracle Website.

Regards

Raza
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
Please do not confuse synchronization with serialization. Methods
wait() and notify() are so important to Java that they will never
be dropped from the exam. Just consider that they are members
of the Object class. I can see where serialization may not receive
a lot of attention.

Jim ... ...


BEE MBA PMP SCJP-6
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
I cannot see "Serialization" as well as "wait , notify and notifyAll" on Exam anymore ( in accordance to Oracle site)

But as said by Ankit, it is better to do them , because if it would come there is no body to listen.
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
Is it true that Java threads are no longer on the exam? I can't see how
you could answer questions about threads without knowing a lot about
how wait() and notify() function. Please advise.

Jim ... ...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9317
    
  17

Threads are on the exam. There are a lot of things about threads other than wait and notify. This is from the SCJP objectives from Oracle's site
  • Write code to define, instantiate, and start new threads using both java.lang.Thread and java.lang.Runnable.
  • Recognize the states in which a thread can exist, and identify ways in which a thread can transition from one state to another.
  • Given a scenario, write code that makes appropriate use of object locking to protect static or instance variables from concurrent access problems
  • Sahil Kapoor
    Ranch Hand

    Joined: Sep 12, 2009
    Posts: 316
    Jim Hoglund wrote:Is it true that Java threads are no longer on the exam? I can't see how
    you could answer questions about threads without knowing a lot about
    how wait() and notify() function. Please advise.

    Jim ... ...



    Dear , just "wait(), notify() and notifyAll()" are removed .

     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Threads Threads and Threads