### Question:
Threads { public static void sleepWithoutInterrupt(final long msToWait) { long timeMillis = System.currentTimeMillis(); long endTime = timeMillis + msToWait; boolean interrupted = false; while (timeMillis < endTime) { try { Thread.sleep(endTime - timeMillis); } catch (InterruptedException ex) { interrupted = true; } timeMillis = System.currentTimeMillis(); } if (interrupted) { Thread.currentThread().interrupt(); } }  static Thread setDaemonThreadRunning(final Thread t); static Thread setDaemonThreadRunning(final Thread t,
    final String name); static Thread setDaemonThreadRunning(final Thread t,
    final String name, final UncaughtExceptionHandler handler); static void shutdown(final Thread t); static void shutdown(final Thread t, final long joinwait); static void threadDumpingIsAlive(final Thread t); static void sleep(long millis); static void sleepWithoutInterrupt(final long msToWait); static ThreadPoolExecutor getBoundedCachedThreadPool(
      int maxCachedThread, long timeout, TimeUnit unit,
      ThreadFactory threadFactory); static ThreadFactory getNamedThreadFactory(final String prefix); static ThreadFactory newDaemonThreadFactory(final String prefix);  }### Answer:
@Test(timeout=6000) public void testSleepWithoutInterrupt() throws InterruptedException { Thread sleeper = new Thread(new Runnable() { @Override public void run() { LOG.debug("Sleeper thread: sleeping for " + SLEEP_TIME_MS); Threads.sleepWithoutInterrupt(SLEEP_TIME_MS); LOG.debug("Sleeper thread: finished sleeping"); wasInterrupted = Thread.currentThread().isInterrupted(); } }); LOG.debug("Starting sleeper thread (" + SLEEP_TIME_MS + " ms)"); sleeper.start(); long startTime = System.currentTimeMillis(); LOG.debug("Main thread: sleeping for 500 ms"); Threads.sleep(500); LOG.debug("Interrupting the sleeper thread and sleeping for 2000 ms"); sleeper.interrupt(); Threads.sleep(2000); LOG.debug("Interrupting the sleeper thread and sleeping for 1000 ms"); sleeper.interrupt(); Threads.sleep(1000); LOG.debug("Interrupting the sleeper thread again"); sleeper.interrupt(); sleeper.join(); assertTrue("sleepWithoutInterrupt did not preserve the thread's " + "interrupted status", wasInterrupted); long timeElapsed = System.currentTimeMillis() - startTime; assertTrue("Elapsed time " + timeElapsed + " ms is out of the expected " + "range of the sleep time " + SLEEP_TIME_MS, Math.abs(timeElapsed - SLEEP_TIME_MS) < TOLERANCE_MS); LOG.debug("Target sleep time: " + SLEEP_TIME_MS + ", time elapsed: " + timeElapsed); }