Mark,
Im sure you dont do 'lock' if you dont have these waiting/sleeping/blocking issues.
So what i meant the overall synchronization of multiple threads that trying to access a concurrent object. Even so acquiring and releasing locks regardless how short it is has an overhead than normal..
here's an example for singleton that is multi-threaded safe but needs optimization:
Code:
public class Singleton {
private static Singleton instance = null;
// this is already a threadsafe for multi-threaded envs,
// but synchronized is an overhead
// and you dont really need this all the time since
// initialization of the instance is just happening once
public synchronized static Singleton getInstance() {
if (instance == null) {
instance = new Singleton();
}
return instance;
}
}