List of usage examples for java.lang Thread currentThread
@HotSpotIntrinsicCandidate public static native Thread currentThread();
From source file:Main.java
/** * Returns a readable name of the current executing thread. *//*from www. j av a2s. c o m*/ public static final String currentThreadInfo() { Thread thread = Thread.currentThread(); return String.valueOf(thread.getName() + "@" + thread.hashCode()); }
From source file:Main.java
public static void sleep(long millis) { if (millis > 0) { try {/*from w w w . j a v a2 s . c o m*/ Thread.sleep(millis); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }
From source file:Main.java
public static int getCurrentThreadId() { return Integer.parseInt(Thread.currentThread().getName()); }
From source file:Main.java
public static String getThreadSignature() { Thread t = Thread.currentThread(); long id = t.getId(); String name = t.getName();// ww w .j ava 2s . com long pri = t.getPriority(); String gname = t.getThreadGroup().getName(); return (name + ":(id)" + id + ":(priority)" + pri + ":(group)" + gname); }
From source file:Main.java
/** * If the thread has been interrupted, throws an InterruptedException. *///from ww w.j av a2s. co m public static void checkForInterruption() throws InterruptedException { if (Thread.currentThread().isInterrupted()) throw new InterruptedException(); }
From source file:Main.java
public static String getClass(int N) { StackTraceElement ste = Thread.currentThread().getStackTrace()[N]; return ste.getClassName(); }
From source file:Main.java
public static void sleep(long durationMillis) { try {/* ww w .j a va2s .c o m*/ Thread.sleep(durationMillis); } catch (InterruptedException var3) { Thread.currentThread().interrupt(); } }
From source file:Main.java
public static String getMethodName() { return Thread.currentThread().getStackTrace()[1].getMethodName(); }
From source file:Main.java
/** * Sleep thread for seconds.//from w w w.j ava2 s .c om * * @param milisecond */ public static void sleepForInSecs(Integer milisecond) { try { // do what you want to do before sleeping Thread.currentThread().sleep(milisecond);// sleep for 1000 ms // do what you want to do after sleeptig } catch (InterruptedException ie) { // If this thread was intrrupted by nother thread ie.printStackTrace(); } }
From source file:Main.java
/** * @return true if the current thread was created by TestNG. *///w w w . j a va 2s . co m public static boolean isTestNGThread() { return Thread.currentThread().getName().contains(THREAD_NAME); }