code: public static void sleep(int ms) {
        long deadline = System.currentTimeMillis() + ms;
        while (System.currentTimeMillis() < deadline) {
           try {
              Thread.sleep(Math.max(1, (deadline - System.currentTimeMillis()) / 2));
           } catch (InterruptedException ignore) {}
        }
     }
docs: Sleeps for the provided amount of milliseconds, ignoring thread
  interrupts.
  
  @param ms
  how many milliseconds to sleep