Class ThreadUtil

java.lang.Object
org.apache.hadoop.util.ThreadUtil

@Evolving public class ThreadUtil extends Object
  • Constructor Details

    • ThreadUtil

      public ThreadUtil()
  • Method Details

    • sleepAtLeastIgnoreInterrupts

      public static void sleepAtLeastIgnoreInterrupts(long millis)
      Cause the current thread to sleep as close as possible to the provided number of milliseconds. This method will log and ignore any InterruptedException encountered.
      Parameters:
      millis - the number of milliseconds for the current thread to sleep
    • joinUninterruptibly

      public static void joinUninterruptibly(Thread toJoin)
      Join a thread as uninterruptible. The call continues to block until the result is available even when the caller thread is interrupted. The method will log any InterruptedException then will re-interrupt the thread.
      Parameters:
      toJoin - the thread to Join on.
    • getResourceAsStream

      public static InputStream getResourceAsStream(String resourceName) throws IOException
      Convenience method that returns a resource as inputstream from the classpath.

      Uses the Thread's context classloader to load resource.

      Parameters:
      resourceName - resource to retrieve.
      Returns:
      inputstream with the resource.
      Throws:
      IOException - thrown if resource cannot be loaded
    • getResourceAsStream

      public static InputStream getResourceAsStream(ClassLoader cl, String resourceName) throws IOException
      Convenience method that returns a resource as inputstream from the classpath using given classloader.

      Parameters:
      cl - ClassLoader to be used to retrieve resource.
      resourceName - resource to retrieve.
      Returns:
      inputstream with the resource.
      Throws:
      IOException - thrown if resource cannot be loaded