public class ThreadTest implements Runnable { static int next_id=1; boolean keepRunning = true; int snooze; int id; public ThreadTest() { this( 1000 ); } public ThreadTest(int milliseconds) { snooze = milliseconds; id = next_id++; //id = System.currentTimeMillis(); //long } public void run() { while (keepRunning) { try { Thread.sleep(snooze); } catch (InterruptedException e) { System.out.println("InterruptedException caught"); } System.out.println(this); } } public void pleaseStop() { keepRunning = false; System.out.println("thread "+this+" terminating"); } public void pleasePause() { try { //dummy_waiter.pause(); } catch (IllegalMonitorStateException e) { System.out.println("thread "+this+" IllegalMonitorStateException"); } System.out.println("thread "+this+" pausing"); } public void pleaseContinue() { try { // dummy_waiter.continu(); } catch (IllegalMonitorStateException e) { System.out.println("thread "+this+" IllegalMonitorStateException"); } System.out.println("thread "+this+" continuing"); } public void updateSnooze(int newSnooze) { snooze = newSnooze; System.out.println("thread "+this+" new snooze"); } public String toString() { return Integer.toString(id) + " " + Integer.toString(snooze); } /* //doesn't work public static class waiter { //dummy class so threads have some object to wait and notify on?? public synchronized void pause() { try { System.out.println("waiter pause"); this.wait(); } catch (InterruptedException e) { System.out.println("waiter InterruptedException"); } } public synchronized void continu() { System.out.println("waiter continu"); this.notify(); } } waiter dummy_waiter = new waiter(); */ }