org.apache.hadoop.util

## Class ThreadUtil

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

-     @InterfaceStability.Evolving
      public class ThreadUtil
      extends Object

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ThreadUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static InputStream` | `getResourceAsStream(ClassLoader cl, String resourceName)` Convenience method that returns a resource as inputstream from the classpath using given classloader.
    `static InputStream` | `getResourceAsStream(String resourceName)` Convenience method that returns a resource as inputstream from the classpath.
    `static void` | `joinUninterruptibly(Thread toJoin)` Join a thread as uninterruptible.
    `static void` | `sleepAtLeastIgnoreInterrupts(long millis)` Cause the current thread to sleep as close as possible to the provided number of milliseconds.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ThreadUtil

          public ThreadUtil()

  - ### Method Detail

    - #### 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

Copyright © 2008–2022 Apache Software Foundation. All rights reserved.