@Test(expected = AssertionError.class) public void stop_thread_before_starting() throws Exception { WorkerThread wt = new WorkerThread("x"); wt.stop(); }
@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(); Thread t = m_thread; while (t.isAlive()) { try { interrupt_wait(); wait(THREAD_STATE_POLL_TIME_MS); } catch (InterruptedException e) { } } if (m_thread != null) { m_state = WtState.STOPPED; fire_state_changed(); m_thread = null; } else { assert m_state == WtState.ABORTED; } }
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(); Thread t = m_thread; while (t.isAlive()) { try { interrupt_wait(); wait(THREAD_STATE_POLL_TIME_MS); } catch (InterruptedException e) { } } if (m_thread != null) { m_state = WtState.STOPPED; fire_state_changed(); m_thread = null; } else { assert m_state == WtState.ABORTED; } } }
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(); Thread t = m_thread; while (t.isAlive()) { try { interrupt_wait(); wait(THREAD_STATE_POLL_TIME_MS); } catch (InterruptedException e) { } } if (m_thread != null) { m_state = WtState.STOPPED; fire_state_changed(); m_thread = null; } else { assert m_state == WtState.ABORTED; } } WorkerThread(String name); }
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(); Thread t = m_thread; while (t.isAlive()) { try { interrupt_wait(); wait(THREAD_STATE_POLL_TIME_MS); } catch (InterruptedException e) { } } if (m_thread != null) { m_state = WtState.STOPPED; fire_state_changed(); m_thread = null; } else { assert m_state == WtState.ABORTED; } } WorkerThread(String name); void add_listener(WorkerThreadListener l); void remove_listener(WorkerThreadListener l); @Override String name(); @Override synchronized String description(); @Override synchronized ThrowableCollector collector(); @Override final synchronized WtState state(); @Override final synchronized void start(); @Override final synchronized void stop(); }
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(); Thread t = m_thread; while (t.isAlive()) { try { interrupt_wait(); wait(THREAD_STATE_POLL_TIME_MS); } catch (InterruptedException e) { } } if (m_thread != null) { m_state = WtState.STOPPED; fire_state_changed(); m_thread = null; } else { assert m_state == WtState.ABORTED; } } WorkerThread(String name); void add_listener(WorkerThreadListener l); void remove_listener(WorkerThreadListener l); @Override String name(); @Override synchronized String description(); @Override synchronized ThrowableCollector collector(); @Override final synchronized WtState state(); @Override final synchronized void start(); @Override final synchronized void stop();  }