I am trying to see the difference between "applying a ReentrantReadWriteLock to a static method" and "applying a ReentrantReadWriteLock to a non-static method". I thought it should be the same, but somehow I thought it should have some difference. I got myself in a unclear state. Can anyone help me out? By the way, I defined these set of static methods in a cache utility class to add/remove/invalidate cache.
or this is a lower level question? what the pro and cons on static method comparing to regular method in a multi-threaded environment?
Ricky:what the pro and cons on static method comparing to regular method in a multi-threaded environment?
I dont think there is a point in talking about methods being static or not, it is the data that is to be made threadsafe. Any data in a multi-threaded environment must be protected using various synchronization technique. Static data is shared by all the instances of the class (or by calling programs if there are no instances) So, when there are a lot of instances of a class, static data it is more prone to corruption by multiple threads as compared to instance data. Other than this there is no real difference in making a static/instance data threadsafe.