aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes confusions around thread functions .. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "confusions around thread functions .." Watch "confusions around thread functions .." New topic
Author

confusions around thread functions ..

Shrini Kulkarni
Ranch Hand

Joined: Jan 12, 2001
Posts: 63
Hi,
After going thru 4-5 different sources of study materials on Thread ( RHE, KAM, maha's site, etc) Here are few of my comments
on threads - methods - in general ...
1. Every Java object is provided with methods like wait(),
notify(), notifyAll() for thread synchronization and Thread safe design. Use word synchronized for methods in class to make them accessed by one only thread at a time. A general layout for a synchronized method is like this
public synchronized void doSomeThing()
{
while (//test some instance variable )
{
try{
wait(); // ask all the threads entering this method to
// wait !!
catch (InterruptedException e)}{}
}
// Do some automic operations
// Change the object status
notify() // notify that object has chaged its status and
// one of the wating threads can ente the method
}

Let me know your views on this general layout !!
2. Methods like sleep(), yield() are not called in shared object
(class's ) code as object yeilding or sleeping does not make sense insted it the thread that sleeps or yields.. They are called in threads code.
To conclude :
Following methods are used in thread or runnable class
sleep(), yield()
start(), run(), interrupt()
Following methods are used in any shared object class :
like MailBox class
wait(), notify() and notifyAll()
Please bear with me my way of asking question was wrong and confusing ... I just want to clarify my understanding of threads..
BTW I am appearing exam on Feb 23rd ...
Shrinivas

Sun Certified programmer for Java2 platform.<BR>Shri_mk@hotmail.com
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: confusions around thread functions ..
 
Similar Threads
beginner Thread chart
Exam Qs on Threads- help!
From Velmurugan's Notes
Summary of wait() notify() join() and synchronized
directly stopping a thread