Originally posted by Ashish Agrawal:
As much as i know we can only synchronize method (instance methods and static methods).
I think you are looking for a synchronized block:
If you synchronize a number of critical sections on the "this" handle, it has the effect of locking all those critical sections on the one particular instance of SomeClass (this would look more impressive if we had more than one critical section, of course). You can do the same for member variables of a class where critical sections depend on them.
Furthermore, synchronizing a static method has the effect of locking the corresponding Class object, so I think all the functionality you desire is alreadly there.