synchronized method and synchronized static method :
key point1:
synchronized void foo() {
...
}
is same as
void foo() {
synchronized(this) {
...
}
}
synchronized static void foo() {
...
}
is same as
static void foo() {
synchronized(SomeClass.class) {
...
}
}
key point2:
You can use any object as the lock. If you want to lock subsets of method or static methods.
class SomeClass {
private static final Object LOCK_1 = new Object() {};
private static final Object LOCK_2 = new Object() {};
void foo() {
synchronized(LOCK_1) {...}
}
static void fee() {
synchronized(LOCK_2) {...}
}
}
refer:
http://stackoverflow.com/questions/578904/how-do-synchronized-static-methods-work-in-java