class MyClass {
synchronized void yack(long id) {
for(int x = 1; x < 3; x++) {
System.out.print(id + " ");
Thread.yield();
}
}
}
public class MainClass implements Runnable {
MyClass c;
public static void main(String[] args) {
new MainClass().go();
}
void go() {
c = new MyClass();
new Thread(new MainClass()).start();
new Thread(new MainClass()).start();
}
public void run() {
c.yack(Thread.currentThread().getId());
}
}
|