package blockingtest;
/**
* Hello world!
*/
public class Sync implements Runnable {
int n;
public static void main(String[] args) {
Sync sync = new Sync();
new Thread(sync, "Sync1").start();
new Thread(sync, "Sync2").start();
new Thread(sync, "Sync3").start();
}
public void run() {
for (int i = 0; i < 3; i++) {
inc();
}
}
public synchronized void inc() {
n++;
System.out.print(Thread.currentThread().getName() + "\n");
try {
Thread.sleep(10000);
} catch (Exception ex) {
System.out.print(ex.getMessage());
}
}
}