dcsimg
Question about wait and notifyAll.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   George_Simple
Posted On:   Tuesday, March 18, 2003 04:31 AM

Hi, everyone! I have only noticed that notifyAll and wait are invoked in a class that extents the thread class or implements runable interface. But there is a piece of code like the following, -------- //class A is not a class that extends thread or //implements runable class A { private static resourceC; public void methodB(String someargs) { //check the status of resourceC wait(some time); //do some business with resourceC } public void methodD(String someargs) { //check the status of resourceC notifyAll(); //do some business with resourceC }    More>>
			
Hi, everyone!


I have only noticed that notifyAll and wait are
invoked in a class that extents the thread class
or implements runable interface.


But there is a piece of code like the following,

--------
//class A is not a class that extends thread or
//implements runable
class A
{
private static resourceC;

public void methodB(String someargs)
{
//check the status of resourceC
wait(some time);
//do some business with resourceC
}

public void methodD(String someargs)
{
//check the status of resourceC
notifyAll();
//do some business with resourceC
}

}
--------


I wondered whether we can call notifyAll or wait
method outside a class that is not extended from
thread or implemented from runable?

BTW: The above class is a class that is invoked by some
servlets of a web server.

Who can give me a simple explanation?


Thanks in advance,
George
   <<Less

Re: Question about wait and notifyAll.

Posted By:   Lasse_Koskela  
Posted On:   Tuesday, March 18, 2003 05:56 AM

The Object.wait() and Object.notifyAll() methods are related to synchronizing and can be called for a non-threaded object.


The wait() method means semantically "I want a lock on this object, tell me when it is available". The notifyAll() method means semantically "notify all awaiting threads that I'm done".


Was that helpful or did I make things worse?

About | Sitemap | Contact