Package org.apache.hadoop.util
Class ThreadUtil
java.lang.Object
org.apache.hadoop.util.ThreadUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic InputStreamgetResourceAsStream(ClassLoader cl, String resourceName) Convenience method that returns a resource as inputstream from the classpath using given classloader.static InputStreamgetResourceAsStream(String resourceName) Convenience method that returns a resource as inputstream from the classpath.static voidjoinUninterruptibly(Thread toJoin) Join a thread as uninterruptible.static voidsleepAtLeastIgnoreInterrupts(long millis) Cause the current thread to sleep as close as possible to the provided number of milliseconds.
-
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 anyInterruptedExceptionencountered.- Parameters:
millis- the number of milliseconds for the current thread to sleep
-
joinUninterruptibly
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 anyInterruptedExceptionthen will re-interrupt the thread.- Parameters:
toJoin- the thread to Join on.
-
getResourceAsStream
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
-