Question about synchronized and wait
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   George_Simple
Posted On:   Tuesday, March 18, 2003 09:15 PM

Hi, everyone! If a thread enters a piece of code that is marked as synchronized, then the thread invoke wait(some time) in the same function. Can other thread enter the same region that is marked as synchronized? (I mean in the critical region there is no active thread but only waiting thread.) For example: -------- public synchronized void functionA () { //check something wait(3000); //do some thing else } -------- If thread A enters function functionA and after "check something", it wait for a notification. Then thread B tries to enter the same synchronized function. Can thread B enters functionA w   More>>
			
Hi, everyone!


If a thread enters a piece of code that is marked
as synchronized, then the thread invoke wait(some time) in the same function.
Can other thread enter the same region that is marked as synchronized?
(I mean in the critical region there is no active thread but only waiting thread.)

For example:

--------
public synchronized void functionA ()
{
//check something
wait(3000);
//do some thing else
}
--------

If thread A enters function functionA and after "check something", it
wait for a notification. Then thread B tries to enter the same synchronized
function. Can thread B enters functionA when thread A is waiting for a
notification in functionA?


Thanks in advance,
George
   <<Less

Re: Question about synchronized and wait

Posted By:   Anonymous  
Posted On:   Wednesday, March 19, 2003 01:18 AM

Hi George,

See the documentation provided for 'wait()' method.
http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html#wait().In specific, observe the following line in the documentation; This method causes the current thread (call it T) to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object .Obviously, thread B can enter functionA when thread A is waiting for a notification in functionA.
About | Sitemap | Contact