1 4 package com.tc.util.concurrent; 5 6 import com.tc.util.Assert; 7 8 13 public class ThreadUtil { 14 15 public static void reallySleep(long millis) { 16 reallySleep(millis, 0); 17 } 18 19 public static void reallySleep(long millis, int nanos) { 20 try { 21 long millisLeft = millis; 22 while (millisLeft > 0 || nanos > 0) { 23 long start = System.currentTimeMillis(); 24 Thread.sleep(millisLeft, nanos); 25 millisLeft -= System.currentTimeMillis() - start; 26 nanos = 0 ; } 28 } catch (InterruptedException ie) { 29 Assert.eval(false); 30 } 31 } 32 33 37 public static boolean tryToSleep(long millis) { 38 boolean slept = false; 39 try { 40 Thread.sleep(millis); 41 slept = true; 42 } catch (InterruptedException ie) { 43 slept = false; 44 } 45 return slept; 46 } 47 48 public static void printStackTrace(StackTraceElement ste[]) { 49 for (int i = 0; i < ste.length; i++) { 50 System.err.println("\tat " + ste[i]); 51 } 52 } 53 } | Popular Tags |