Package org.jboss.netty.util
Class VirtualExecutorService
java.lang.Object
java.util.concurrent.AbstractExecutorService
org.jboss.netty.util.VirtualExecutorService
- All Implemented Interfaces:
Executor
,ExecutorService
A delegating The differences from an ordinary
A shutdown request (
ExecutorService
with its own termination management.
VirtualExecutorService
is used when you want to inject an
ExecutorService
but you do not want to allow the explicit termination
of threads on shutdown request. It is particularly useful when the
ExecutorService
to inject is shared by different components and
the life cycle of the components depend on the termination of the injected
ExecutorService
.
ExecutorService globalExecutor = ...; ExecutorService virtualExecutor = newVirtualExecutorService
(globalExecutor);ChannelFactory
factory = newNioServerSocketChannelFactory
(virtualExecutor, virtualExecutor); ... // ChannelFactory.releaseExternalResources() shuts down the executor and // interrupts the I/O threads to terminate all I/O tasks and to release all // resources acquired by ChannelFactory. factory.releaseExternalResources(); // Note that globalExecutor is not shut down because VirtualExecutorService // implements its own termination management. All threads which were acquired // by ChannelFactory via VirtualExecutorService are returned to the pool. assert !globalExecutor.isShutdown();
The differences from an ordinary ExecutorService
A shutdown request (shutdown()
or shutdownNow()
) does not
shut down its parent Executor
but simply sets its internal flag to
reject further execution request.
shutdownNow()
interrupts only the thread which is executing the
task executed via VirtualExecutorService
.
awaitTermination(long, TimeUnit)
does not wait for real thread
termination but wait until VirtualExecutorService
is shut down and
its active tasks are finished and the threads are returned to the parent
Executor
.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Executor
private final ExecutorService
(package private) boolean
(package private) final Object
-
Constructor Summary
ConstructorsConstructorDescriptionVirtualExecutorService
(Executor parent) Creates a new instance with the specified parentExecutor
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
awaitTermination
(long timeout, TimeUnit unit) void
boolean
boolean
void
shutdown()
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
-
Field Details
-
e
-
s
-
startStopLock
-
shutdown
volatile boolean shutdown -
activeThreads
-
-
Constructor Details
-
VirtualExecutorService
Creates a new instance with the specified parentExecutor
.
-
-
Method Details
-
isShutdown
public boolean isShutdown() -
isTerminated
public boolean isTerminated() -
shutdown
public void shutdown() -
shutdownNow
-
awaitTermination
- Throws:
InterruptedException
-
execute
-