• 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

confusions around thread functions ..

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic