Home arrow static arrow Java Programming [Archive] - Class Locking? Is this possible?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Class Locking? Is this possible?
This topic has 4 replies on 1 page.

Posts:754
Registered: 6/13/03
Class Locking? Is this possible?  
Jul 30, 2004 2:33 AM



 
Hi,

Can a class be locked? Is this possible?
Can someone show me a code for this?

rgds
 

Posts:10
Registered: 6/3/04
Re: Class Locking? Is this possible?  
Jul 30, 2004 2:34 AM (reply 1 of 4)



 
What exactly do you mean by "locking"?!
 

Posts:4,496
Registered: 19/06/02
Re: Class Locking? Is this possible?  
Jul 30, 2004 2:46 AM (reply 2 of 4)



 
Synchronize a static method.
Call the synchronized method.
The Class Object is now locked.
 

Posts:18,384
Registered: 21.03.00
Re: Class Locking? Is this possible?  
Jul 30, 2004 4:06 AM (reply 3 of 4)



 
Hi,

synchronized (Test.class) {    // Has monitor lock for the Test class}


/Kaj
 

Posts:4,496
Registered: 19/06/02
Re: Class Locking? Is this possible?  
Jul 30, 2004 4:34 AM (reply 4 of 4)



 
It's worth pointing out that, because a synchronized non-static method doesn't lock the Class Object monitor, a thread can enter a synchronized non-static method and modify static (class) variables even if you have locked the Class Object.
 
This topic has 4 replies on 1 page.