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