class WorkerThread implements WorkerThreadCI {

	@Override
	public final synchronized void stop() {
		Ensure.is_true(m_state == WtState.RUNNING,
				"w_state != WtState.RUNNING");
		
		if (Thread.currentThread() == m_thread) {
			throw new ClosingWorkerThreadFromWithinException();
		}
		
		m_state = WtState.STOPPING;
		fire_state_changed();
		
		/*
		 * We need to save t as the thread may abort during wait...
		 */
		Thread t = m_thread;
		while (t.isAlive()) {
			try {
				interrupt_wait();
				wait(THREAD_STATE_POLL_TIME_MS);
			} catch (InterruptedException e) {
				/*
				 * We'll just cycle again faster.
				 */
			}
		}
		
		if (m_thread != null) {
			m_state = WtState.STOPPED;
			fire_state_changed();
			m_thread = null;
		} else {
			assert m_state == WtState.ABORTED;
		}
	}

	public  WorkerThread(String name);

}