Package ej.basictool

Class ThreadUtils


  • public class ThreadUtils
    extends Object
    Provides utility methods related to threads.
    • Method Detail

      • sleep

        public static void sleep​(long millis)
        Delays the execution of the current thread. This convenience method may be used instead of Thread.sleep(long) to avoid the necessity of catching the InterruptedException.
        Parameters:
        millis - the execution delay, in milliseconds.
      • handleUncaughtException

        public static void handleUncaughtException​(Throwable t)
        Handles Throwable (either an exception or an error) which has not been caught in a particular scope. If the UncaughtExceptionHandler of the current thread has been set, it is used to handle the Throwable. If not set, the default UncaughtExceptionHandler is used instead. If not set either, the stack trace of the Throwable is printed. The following example shows how this method may be used:
         try {
                connectionListener.onDisconnected();
         } catch (Throwable t) {
                ThreadUtils.handleUncaughtException(t);
         }
         
        Parameters:
        t - the Throwable to handle.