Package jetbrains.buildServer.util
Class ThreadUtil
- java.lang.Object
-
- jetbrains.buildServer.util.ThreadUtil
-
public final class ThreadUtil extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
awaitLatch(CountDownLatch latch)
static void
shutdownGracefully(ExecutorService service, String identifier)
Gracefully stops executor tasks: stops executor, then waits for some time, then tries to interrupt running tasks and waits for termination of the executor.static void
shutdownGracefully(ExecutorService service, String identifier, long shutdownAwaitTimeout, long shutdownNowAwaitTimeout)
Gracefully stops executor tasks: stops executor, then waits for some time, then tries to interrupt running tasks and waits for termination of the executor.static void
shutdownNowAndWait(ExecutorService service, String identifier)
Interrupts executor tasks and waits for executor to finish.static void
sleep(long millis)
Sleeps for the specified time.static Map<Future,Throwable>
waitForTasks(Collection<Future> futures)
Waits for futures to complete, returns all errors occurred during the waiting.
-
-
-
Method Detail
-
shutdownGracefully
public static void shutdownGracefully(@NotNull ExecutorService service, @NotNull String identifier)
Gracefully stops executor tasks: stops executor, then waits for some time, then tries to interrupt running tasks and waits for termination of the executor.- Parameters:
service
- executor to shut downidentifier
- executor identifier to use in log messages
-
shutdownGracefully
public static void shutdownGracefully(@NotNull ExecutorService service, @NotNull String identifier, long shutdownAwaitTimeout, long shutdownNowAwaitTimeout)
Gracefully stops executor tasks: stops executor, then waits for some time, then tries to interrupt running tasks and waits for termination of the executor.- Parameters:
service
- executor to shut downidentifier
- executor identifier to use in log messagesshutdownAwaitTimeout
- timeout in milliseconds to wait for the service shutdownshutdownNowAwaitTimeout
- timeout in milliseconds to wait for the service shutdownNow
-
shutdownNowAndWait
public static void shutdownNowAndWait(@NotNull ExecutorService service, @NotNull String identifier)
Interrupts executor tasks and waits for executor to finish.- Parameters:
service
- executor to shut downidentifier
- executor identifier to use in log messages
-
waitForTasks
@NotNull public static Map<Future,Throwable> waitForTasks(@NotNull Collection<Future> futures)
Waits for futures to complete, returns all errors occurred during the waiting.- Parameters:
futures
- futures- Returns:
- map from future to exception, if error occurred during the waiting.
-
sleep
public static void sleep(long millis)
Sleeps for the specified time.Does like the
Thread.sleep(long)
does but doesn't throw exceptions.- Parameters:
millis
- sleeping time in milliseconds.
-
awaitLatch
public static void awaitLatch(CountDownLatch latch)
-
-