Package es.urjc.etsii.grafo.util
Class ConcurrencyUtil
java.lang.Object
es.urjc.etsii.grafo.util.ConcurrencyUtil
Helper methods to deal with concurrent tasks
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
await
(ExecutorService executor) Awaits termination for the given executor service.static <T> T
Block until the task is completed.static <T> Optional
<T> Block until the task is completed.static <T> List
<T> awaitAll
(Collection<Future<T>> futures) Await a collection of futuresstatic <T> List
<T> Await a stream of futuresstatic void
Sleep without having to deal with InterruptedException
-
Constructor Details
-
ConcurrencyUtil
public ConcurrencyUtil()
-
-
Method Details
-
await
Awaits termination for the given executor service. Wraps InterruptedException in an unchecked RuntimeException- Parameters:
executor
- Executor service
-
await
Block until the task is completed. Wraps the annoying checked exception.- Type Parameters:
T
- Future type- Parameters:
f
- Future we will wait for- Returns:
- SimplifiedResult of the task
- Throws:
RuntimeException
- in case any error happened during the execution
-
await
Block until the task is completed. Handles the exception with the given handler- Type Parameters:
T
- Optional type- Parameters:
f
- Future we will wait forexceptionHandler
- pass the exception to handler instead of promoting to RuntimeException- Returns:
- SimplifiedResult of the task
- Throws:
RuntimeException
- in case any error happened during the execution
-
awaitAll
Await a collection of futures- Type Parameters:
T
- Futures type- Parameters:
futures
- collection of futures- Returns:
- Objects inside futures
-
awaitAll
Await a stream of futures- Type Parameters:
T
- Futures type- Parameters:
futures
- stream of futures- Returns:
- Objects inside futures
-
sleep
Sleep without having to deal with InterruptedException- Parameters:
time
- time to sleepunit
- unit of time
-