ThreadUtils { @SuppressWarnings("deprecation") public static void stopQuietly(Thread thread, String stopMessage) { if (thread == null) { return; } try { thread.join(THREAD_WAITING_TIME); } catch (Exception e) { noOp(); } try { thread.interrupt(); } catch (Exception e) { noOp(); } try { thread.join(RETRY_MILLISECOND); } catch (Exception e) { noOp(); } try { if (thread.isAlive()) { LOGGER.error(stopMessage); thread.stop(); } } catch (Exception e) { noOp(); } }  static void sleep(long millis); @SuppressWarnings("deprecation") static void stopQuietly(Thread thread, String stopMessage);  }
@Test public void testStopQuietly() { Thread newThread = new Thread(new Runnable() { @Override public void run() { int i = 10; while (i > 0) { ThreadUtils.sleep(200); } } }); newThread.start(); ThreadUtils.sleep(500); assertThat(newThread.isAlive()).isTrue(); ThreadUtils.stopQuietly(newThread, "STOPPED!"); ThreadUtils.sleep(1000); assertThat(newThread.isAlive()).isFalse(); }