All pastes #978673 Raw Edit

Mine

public text v1 · immutable
·published 2008-04-09 19:01 UTC
rendered paste body
class Thread2 extends Thread {
	mailbox box;

	Thread2(mailbox box) {
		this.box = box;
		
	}

	synchronized public void run() {
		 for(int i = 0; i<5;i++)
			box.assign(Thread.currentThread().getName());

		 
			


		try{
			this.wait();
			Thread.currentThread().sleep((long)(Math.random()*100000000));
		}catch (InterruptedException e){
			System.exit(1);
		}
	}
}
class ThreadClear extends Thread{
	mailbox box;
	ThreadClear(mailbox box){
		this.box = box;
	}
	synchronized public void run(){
		while(true){
			System.out.println(box.erase());
			notifyAll();
			try{
				Thread.currentThread().sleep((long)(Math.random()*100000000));
			}catch (InterruptedException e){
				System.exit(1);
			}

		}
	}

}


class mailbox {
	String message;
	
	mailbox(String message){
		this.message = message;
	}
	public void assign(String s){
		this.message = s;
	}
	public String erase(){
		String s = message;
		message ="";
		return s;
	}
}


public class Coordination {

	public static void main(String args[]) {
		mailbox box = new mailbox("");
		ThreadClear clear = new ThreadClear(box); 
		clear.start();
		for(int i = 0; i<10;i++){
			Thread2 firstThread = new Thread2(box);
			firstThread.start();
			
			
		}
		
	}
}