public final class ControlFlowUtility extends Object
Modifier and Type | Method and Description |
---|---|
static ExecutorService |
createDaemonExecutorService()
Creates an
ExecutorService which executes tasks as daemon
threads; the Executors.newCachedThreadPool() is being used to do
so. |
static ExecutorService |
createExecutorService()
Returns a default
ExecutorService retrieved from the
Executors . |
static void |
joinFutures(Collection<? extends Future<?>> aFutures)
Joins the
Future instances contained in the given
Collection . |
static void |
joinFutures(Future<?>... aFutures)
Joins the
Future instances contained in the given
Collection . |
static void |
joinThreads(Collection<? extends Thread> aThreads)
Joins the
Thread instances contained in the given
Collection . |
static void |
joinThreads(Thread... aThreads)
Joins the
Thread instances contained in the given
Collection . |
static void |
shutdownGracefully(ExecutorService aExecutorService)
Tries to orderly shutdown (
ExecutorService.shutdown() ) all tasks
of an ExecutorService , after a timeout of
IoRetryCount.NORM milliseconds, shutdown is forced as of
ExecutorService.shutdownNow() .
-------------------------------------------------------------------------
CAUTION: Do only invoke this methods on ExecutorService instances
you manage exclusively yourself, do not apply this method on
ExecutorService instances provided to you by your application
server (e.g. an JEE server) |
static void |
shutdownGracefully(ExecutorService aExecutorService,
long aTimeOutInMs)
Tries to orderly shutdown (
ExecutorService.shutdown() ) all tasks
of an ExecutorService , after a given timeout in milliseconds,
shutdown is forced as of ExecutorService.shutdownNow() . |
static void |
throwIllegalStateException(boolean isIllegalState)
Code redundancy preventing code snippet (in terms of aspect) throwing an
IllegalStateException in case an illegal state false
is being provided. |
static ExecutorService |
toManagedExecutorService(ExecutorService aExecutorService)
Converts an
ExecutorService to be a
ManagedExecutorService with methods
ExecutorService.shutdown() and
ExecutorService.shutdownNow() being disabled as them are to be
managed by an application server. |
static Object |
waitForFutures(Collection<? extends Future<?>> aFutures)
Joins the
Future instances contained in the given
Collection . |
static Object |
waitForFutures(Future<?>... aFutures)
Joins the
Future instances contained in the given
Collection . |
public static void throwIllegalStateException(boolean isIllegalState) throws IllegalStateException
IllegalStateException
in case an illegal state false
is being provided. This method can be called in the beginning of methods
of instances which can be disposed (Disposable
) or destroyed (as
of org.refcodes.component.Destroyable
or decomposed (as of
org.refcodes.component.Decomposeable
). In such cases the
"disposed", "destroyed", "decomposed" or similar flag is being passed.isIllegalState
- When true, then an illegal state is being flagged
which causes the according IllegalStateException
with a
default message being thrown.IllegalStateException
- Thrown in case an instance is in a state
not allowing the invocation of the according method; for calling
that method the instance is in an illegal state.public static void joinThreads(Collection<? extends Thread> aThreads)
Thread
instances contained in the given
Collection
.aThreads
- The Collection
containing the Thread
instances to be joined.public static void joinThreads(Thread... aThreads)
Thread
instances contained in the given
Collection
.aThreads
- The Collection
containing the Thread
instances to be joined.public static void joinFutures(Collection<? extends Future<?>> aFutures)
Future
instances contained in the given
Collection
.aFutures
- The Collection
containing the Future
instances to be joined.public static void joinFutures(Future<?>... aFutures)
Future
instances contained in the given
Collection
.aFutures
- The Collection
containing the Future
instances to be joined.public static Object waitForFutures(Collection<? extends Future<?>> aFutures) throws Exception
Future
instances contained in the given
Collection
. Returns the first result detected or throws the first
Exception
which occurred.aFutures
- The Collection
containing the Future
instances to be joined.Exception
- the exceptionpublic static Object waitForFutures(Future<?>... aFutures) throws Exception
Future
instances contained in the given
Collection
. Returns the first result detected or throws the first
Exception
which occurred.aFutures
- The Collection
containing the Future
instances to be joined.Exception
- the exceptionpublic static void shutdownGracefully(ExecutorService aExecutorService)
ExecutorService.shutdown()
) all tasks
of an ExecutorService
, after a timeout of
IoRetryCount.NORM
milliseconds, shutdown is forced as of
ExecutorService.shutdownNow()
.
-------------------------------------------------------------------------
CAUTION: Do only invoke this methods on ExecutorService
instances
you manage exclusively yourself, do not apply this method on
ExecutorService
instances provided to you by your application
server (e.g. an JEE server).
-------------------------------------------------------------------------aExecutorService
- The service which's threads are to be shut down
soon.public static void shutdownGracefully(ExecutorService aExecutorService, long aTimeOutInMs)
ExecutorService.shutdown()
) all tasks
of an ExecutorService
, after a given timeout in milliseconds,
shutdown is forced as of ExecutorService.shutdownNow()
.
No shutdown is forced in case a timeout of o is being provided.
-------------------------------------------------------------------------
CAUTION: Do only invoke this methods on ExecutorService
instances
you manage exclusively yourself, do not apply this method on
ExecutorService
instances provided to you by your application
server (e.g. an JEE server).
-------------------------------------------------------------------------aExecutorService
- The service which's threads are to be shut down
after the given timeout.aTimeOutInMs
- The timeout after which to force shutdown eventually,
in case 0 is being provided, then no shutdown is being forced (all
threads are executed till them terminate normally).public static ExecutorService toManagedExecutorService(ExecutorService aExecutorService)
ExecutorService
to be a
ManagedExecutorService
with methods
ExecutorService.shutdown()
and
ExecutorService.shutdownNow()
being disabled as them are to be
managed by an application server.
Usually this method is being invoked with an ExecutorService
originating from an application server. See
ManagedExecutorService
for more details.aExecutorService
- The ExecutorService
to be transformed to
a ManagedExecutorService
.ManagedExecutorService
from the provided
ExecutorService
.public static ExecutorService createExecutorService()
ExecutorService
retrieved from the
Executors
.ExecutorService
to be used.public static ExecutorService createDaemonExecutorService()
ExecutorService
which executes tasks as daemon
threads; the Executors.newCachedThreadPool()
is being used to do
so.ExecutorService
running tasks as daemon threads.Copyright © 2018. All rights reserved.