// MyTest.java
public class MyTest {
public static void main(String[] args) {
final ST t = new ST();
new Thread() {
public void run() {
t.f();
}
} .start();
t.g();
}
}
class ST extends Thread {
private int i=0;
public void f() { //synchronized
synchronized (this) {
i=i+2;
System.out.println("f().i="+i);
}
}
public void g() {
synchronized (this) {
i=i-5;
System.out.println("g().i="+i);
}
}
}