ThreadUtil (Apache Hadoop Common 3.5.0 API)
Description: declaration: package: org.apache.hadoop.util, class: ThreadUtil

Package org.apache.hadoop.util

# Class ThreadUtil

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

@Evolving public class ThreadUtil extends Object

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ThreadUtil()`

- ## Method Summary

  Modifier and Type
  Method
  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 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