:arrow: Observando o Código Abaixo, em sua compiliação a mensagem resulta em:
Waiting for R1 to complete, como eu conseguira o segundo estado de espera para R2 :?:
[code] public class Threads1 {
int x = 0;
public class Runner implements Runnable {
public void run() {
synchronized(this){
int current = 0;
for (int i = 0; i < 4; i++) {
current = x;
System.out.print(current + ", ");
x = current + 2;
}
notify();
}
}
}
public static void main(String[] args) {
Threads1 r1 = new Threads1();
Threads1 r2 = new Threads1();
synchronized(r1){
try{
System.out.println("Waiting for R1 to complete");
r1.wait();
}catch(InterruptedException e){}
synchronized(r2){
try{
System.out.println("Waiting for R2 to complete");
r2.wait();
}catch(InterruptedException e){}
System.out.println("Total is"+r1.x);
}
}
}
}
[/code]