import java.util.concurrent.atomic.AtomicBoolean;

public class JavaThread {
	public synchronized void doWait  () throws InterruptedException { this.wait  (); }
	public synchronized void doSignal() throws InterruptedException { this.notify(); }

	public static AtomicBoolean go = new AtomicBoolean( false );

	public static class Signaller extends Thread {
		JavaThread j;
		Signaller(JavaThread j) {
			this.j = j;
		}

		public void run() {
			go.set( true );
			try {
				while( JavaThread.go.get() ) {
					this.j.doSignal();
				}
			} catch(InterruptedException trash) {

			}
		}
	}

	public static void main(String[] args) throws InterruptedException {
		int NoOfTimes = 50000;
		JavaThread j = new JavaThread();
		Signaller s = new Signaller(j);
		s.start();
		while( !JavaThread.go.get() ) {
			Thread.yield();
		}
		long start = System.nanoTime();
		for(int i = 1; i <= NoOfTimes; i += 1) {
			j.doWait();
		}
		long end = System.nanoTime();
		go.set( false );
		s.join();
		System.out.println( (end - start) / NoOfTimes);
	}
}