Package ej.basictool
Class ThreadUtils
- java.lang.Object
-
- ej.basictool.ThreadUtils
-
public class ThreadUtils extends Object
Provides utility methods related to threads.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidhandleUncaughtException(Throwable t)HandlesThrowable(either an exception or an error) which has not been caught in a particular scope.static voidsleep(long millis)Delays the execution of the current thread.
-
-
-
Method Detail
-
sleep
public static void sleep(long millis)
Delays the execution of the current thread. This convenience method may be used instead ofThread.sleep(long)to avoid the necessity of catching theInterruptedException.- Parameters:
millis- the execution delay, in milliseconds.
-
handleUncaughtException
public static void handleUncaughtException(Throwable t)
HandlesThrowable(either an exception or an error) which has not been caught in a particular scope. If theUncaughtExceptionHandler of the current threadhas been set, it is used to handle theThrowable. If not set, thedefault UncaughtExceptionHandleris used instead. If not set either, the stack trace of theThrowableis printed. The following example shows how this method may be used:try { connectionListener.onDisconnected(); } catch (Throwable t) { ThreadUtils.handleUncaughtException(t); }- Parameters:
t- theThrowableto handle.
-
-