class Bob {
private static final Object locke = new Object();
private static volatile int value;
public static void fun(){
synchronized(locke){
value++;
}
}
}
这与在课堂上同步有何不同,即synchronized(Bob.class){...}
class Bob {
private static final Object locke = new Object();
private static volatile int value;
public static void fun(){
synchronized(locke){
value++;
}
}
}
这与在课堂上同步有何不同,即synchronized(Bob.class){...}