public class Programa implements Runnable {
private String a;
public void setId(String id) {
this.a = id;
}
public String getId(){
return this.a;
}
public void run () {
synchronized (a) {
for (int i = 0; i < 10000; i++) {
System.out.print(a);
}
}
}
}
public class Teste {
public static void main(String[] args) throws InterruptedException {
Programa p1 = new Programa();
p1.setId("|");
Thread t1 = new Thread(p1);
Programa p2 = new Programa();
p2.setId("/");
Thread t2 = new Thread(p2);
t1.start();
t2.start();
t1.join();
t2.join();
}
}