1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
import java.util.concurrent.CountDownLatch;
signalStart = new CountDownLatch(1);
signalSent = new CountDownLatch(1);
class Handler implements EBComponent
{
public void handleMessage(EBMessage message)
{
System.err.println("handling starts");
signalSent.countDown();
Thread.sleep(200);
// System.err.println(message.getClass().getName());
System.err.println("handling ends");
}
}
h = new Handler();
EditBus.addToBus(h);
th1 = new Thread(new Runnable() {
public void run()
{
signalStart.await();
System.err.println("th1 will send");
EditBus.send(new PropertiesChanged(null));
System.err.println("th1 after send");
}
});
th1.start();
th2 = new Thread(new Runnable() {
public void run() {
signalSent.await();
th1.interrupt();
Thread.sleep(1000);
EditBus.removeFromBus(h);
}
});
th2.start();
System.err.println("macro done");
signalStart.countDown();
|