Synchronizing static members
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anand_Rajasekar
Posted On:   Sunday, January 6, 2002 01:47 AM

Can I lock class-level (static) variables? A static member attribute can be modified by more than one calling program at a time; can I somehow make sure it's locked? I could think of using something like: synchronized(this.class) inside the method that modifies the variable. Also, I think I will need to make the static variable private. But does it make sense to make it private? Then I would give one public static function that allows modification to this variable. Also, in this method I should use: synchronized(this.class) { // modify the static attribute here. } // End of synchronized block. Will this ensure that no two modifying threa   More>>

Can I lock class-level (static) variables? A static member attribute can be modified by more than one calling program at a time; can I somehow make sure it's locked? I could think of using something like:




synchronized(this.class)


inside the method that modifies the variable. Also, I think I will need to make the static variable private. But does it make sense to make it private? Then I would give one public static function that allows modification to this variable. Also, in this method I should use:



synchronized(this.class) {
// modify the static attribute here.
} // End of synchronized block.


Will this ensure that no two modifying threads can modify it at the same time?

   <<Less

Re: Synchronizing static members

Posted By:   Alex_Chaffee  
Posted On:   Monday, January 14, 2002 11:42 AM

Please search the FAQ first. Typing in "static" into the Search box would have saved you some keystrokes.

Re: Synchronizing static members

Posted By:   Bozidar_Dangubic  
Posted On:   Sunday, January 6, 2002 08:09 AM

yes.
About | Sitemap | Contact