// @topic T11760 Multithreading -- wait-notify-interrupt example 01 // @brief main thread calls <tt>notify()</tt> and <tt>interrupt()</tt> on a waiting worker thread package mth; public class AppMain { public static void main(String[] args) { Thread ct = Thread.currentThread(); System.out.println( "[" + ct.getName() + "] started"); // create the IO thread Thread worker = new Thread( new IOThread() ); // start the IO thread worker.start(); System.out.println( "[" + ct.getName() + "] started " + "[" + worker.getName() + "]"); //try { // needed if calling Thread.sleep() int count = 30; while( count-- != 0 ) { synchronized( worker ) { // send a message to the worker thread worker.notify(); } System.out.println( "[" + ct.getName() + "] notified #" + count ); //Thread.sleep( 0 ); } //} catch( InterruptedException ex ) { //} worker.interrupt(); System.out.println("[" + ct.getName() + "] finished"); } }class AppMain