Home arrow static arrow Java Programming [Archive] - Query on synchronization
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Query on synchronization
This topic has 2 replies on 1 page.

Posts:19
Registered: 12/27/03
Query on synchronization  
Jun 19, 2004 3:44 AM



 
Hi,

I have a query on synchronization. When an object is accessed by two or more threads simultaneously, we use the synchronize keyword to prevent two threads simultaneos access. So on which this lock is obtained either it is on the object or the synchronized methods.

chetana
 

Posts:284
Registered: 5/24/04
Re: Query on synchronization  
Jun 19, 2004 4:08 AM (reply 1 of 2)



 
The lock is obtained for the object as a whole. Actually each object has it's associated Monitor, and every time a thread accesses a synchronized method on an object, it gains that objects' monitors' lock. While a thread owns a lock on an objects' monitor, no other thread can access that objects' synchronized methods.
 

Posts:15
Registered: 12/20/99
Re: Query on synchronization  
Jun 19, 2004 7:44 PM (reply 2 of 2)



 
Note: You can still access an Object's non synchronized methods.
 
This topic has 2 replies on 1 page.