, . . , , .
. 0.
class example extends Thread{
public static volatile int value= 0;
public void run(){
while(true)
unsynchMethod();
}
public void unsynchMethod(){
synchronizedMethod();
for(int i =0; i < 20000;++i)
value++;
for(int i = 0; i < 20000;++i)
value--;
System.out.println(value);
}
public static synchronized void synchronizedMethod(){
}
public static void main(String... args){
example a = new example();
example b = new example();
a.start();
b.start();
}
}
, 0, :
4463
6539
-313
-2401
-3012
...