Class ManagedExecutorService

  • All Implemented Interfaces:
    java.util.concurrent.Executor, java.util.concurrent.ExecutorService


    public class ManagedExecutorService
    extends java.lang.Object
    implements java.util.concurrent.ExecutorService
    Usually ExecutorService instances originating from an application server are wrapped with this ManagedExecutorService.

    The ManagedExecutorService wraps an ExecutorService and prevents execution of the ExecutorService.shutdown() and ExecutorService.shutdownNow() methods (them methods are not delegated and therewith disabled).

    This is helpful when you either expect an ExecutorService passed by an application server or, if none is passed, you retrieve a private ExecutorService yourself:

    In the second case, you might want to shutdown your ExecutorService after usage, in the first case you do not want to do so as the application server is to take care on shutdown. You then do not wrap your private ExecutorService; you do wrap any ExecutorService being passed to you (by an application server).

    Wrapping the ExecutorService being passed from the application server and not wrapping the one you create yourself will enable you to shutdown the ExecutorService in any case; in case it is your private one, it will be shutdown; in case it is the one from the application server, the shutdown calls are just ignored.

    • Constructor Summary

      Constructors 
      Constructor Description
      ManagedExecutorService​(java.util.concurrent.ExecutorService eExecutorService)
      Instantiates a new managed executor service.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean awaitTermination​(long aTimeout, java.util.concurrent.TimeUnit aUnit)
      void execute​(java.lang.Runnable aArg0)
      <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(java.util.Collection<? extends java.util.concurrent.Callable<T>> aTasks)
      <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(java.util.Collection<? extends java.util.concurrent.Callable<T>> aTasks, long aTimeout, java.util.concurrent.TimeUnit aUnit)
      <T> T invokeAny​(java.util.Collection<? extends java.util.concurrent.Callable<T>> aTasks)
      <T> T invokeAny​(java.util.Collection<? extends java.util.concurrent.Callable<T>> aTasks, long aTimeout, java.util.concurrent.TimeUnit aUnit)
      boolean isShutdown​()
      boolean isTerminated​()
      void shutdown​()
      java.util.List<java.lang.Runnable> shutdownNow​()
      java.util.concurrent.Future<?> submit​(java.lang.Runnable aTask)
      <T> java.util.concurrent.Future<T> submit​(java.lang.Runnable aTask, T aResult)
      <T> java.util.concurrent.Future<T> submit​(java.util.concurrent.Callable<T> aTask)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ManagedExecutorService

        public ManagedExecutorService​(java.util.concurrent.ExecutorService eExecutorService)
        Instantiates a new managed executor service.
        Parameters:
        eExecutorService - the e executor service
    • Method Detail

      • awaitTermination

        public boolean awaitTermination​(long aTimeout,
                                        java.util.concurrent.TimeUnit aUnit)
                                 throws java.lang.InterruptedException
        Specified by:
        awaitTermination in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
      • execute

        public void execute​(java.lang.Runnable aArg0)
        Specified by:
        execute in interface java.util.concurrent.Executor
      • invokeAll

        public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(java.util.Collection<? extends java.util.concurrent.Callable<T>> aTasks,
                                                                            long aTimeout,
                                                                            java.util.concurrent.TimeUnit aUnit)
                                                                     throws java.lang.InterruptedException
        Specified by:
        invokeAll in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
      • invokeAll

        public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(java.util.Collection<? extends java.util.concurrent.Callable<T>> aTasks)
                                                                     throws java.lang.InterruptedException
        Specified by:
        invokeAll in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
      • invokeAny

        public <T> T invokeAny​(java.util.Collection<? extends java.util.concurrent.Callable<T>> aTasks,
                               long aTimeout,
                               java.util.concurrent.TimeUnit aUnit)
                        throws java.lang.InterruptedException,
                               java.util.concurrent.ExecutionException,
                               java.util.concurrent.TimeoutException
        Specified by:
        invokeAny in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException
      • invokeAny

        public <T> T invokeAny​(java.util.Collection<? extends java.util.concurrent.Callable<T>> aTasks)
                        throws java.lang.InterruptedException,
                               java.util.concurrent.ExecutionException
        Specified by:
        invokeAny in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • isShutdown

        public boolean isShutdown​()
        Specified by:
        isShutdown in interface java.util.concurrent.ExecutorService
      • isTerminated

        public boolean isTerminated​()
        Specified by:
        isTerminated in interface java.util.concurrent.ExecutorService
      • shutdown

        public void shutdown​()
        Specified by:
        shutdown in interface java.util.concurrent.ExecutorService
      • shutdownNow

        public java.util.List<java.lang.Runnable> shutdownNow​()
        Specified by:
        shutdownNow in interface java.util.concurrent.ExecutorService
      • submit

        public <T> java.util.concurrent.Future<T> submit​(java.util.concurrent.Callable<T> aTask)
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
      • submit

        public <T> java.util.concurrent.Future<T> submit​(java.lang.Runnable aTask,
                                                         T aResult)
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
      • submit

        public java.util.concurrent.Future<?> submit​(java.lang.Runnable aTask)
        Specified by:
        submit in interface java.util.concurrent.ExecutorService