" public static Object locker = ...
public static int x = 1;
public static void increment() {
synchronized( locker ) {
x = x + 1;
}
}
"
should be replaced with
public static int x = 1;
public static synchronized void increment() {
x = x + 1;
}
as it is otherwise not guarranted to work as expected when multiple threads are involved (lookup articles on javaworld.com and postings in comp.lang.java.programmer if you don't believe me...
|