transparent
import java.util.Random; class Main{ public static void main(String[] args){ Vide v= new Vide(); Thread t1 = new Proc("un",v); Thread t2 = new Proc("deux",v); Thread t3 = new Proc("trois",v); t1.start();t2.start();t3.start(); } } class Vide{}; class Proc extends Thread{ Vide v; public Proc(String n, Vide v){ super(n); this.v = v; } // ...
//... public void run(){ int p; Random rand = new Random(); while (true){ try { p=Math.abs(rand.nextInt()%5000); sleep(p); synchronized(v){ System.out.println(getName()+ " début de em" ); p=Math.abs(rand.nextInt()%5000); sleep(p); System.out.println(getName()+ " fin de em"); } } catch (InterruptedException e){} } } }