Simple question:
Why would this be preferable:
public class Foo { final private static Object foo = new Object(); public static void doSomething() { synchronized(Foo.foo) {
above this:
public class Foo { public static void doSomething() { synchronized(Foo.class) {
or that:
public class Foo { public synchronized static void doSomething() {
?
For me, these all look essentially the same, so I'm not sure what would be the best way to synchronize access to static fields, or why one would be better than the other, but I heard that the former is often preferable.
source share