Class ConcurrencyUtil


  • public class ConcurrencyUtil
    extends Object
    Utility class to manage creation and shutting down instance of the ThreadPoolExecutor.
    • Constructor Detail

      • ConcurrencyUtil

        public ConcurrencyUtil()
    • Method Detail

      • createThreadPoolExecutor

        public static ThreadPoolExecutor createThreadPoolExecutor​(int parallelism)
        Creates a ThreadPoolExecutor with fixed number of threads which is equal to parallelism.
        Parameters:
        parallelism - number of threads for the executor
        Returns:
        created executor
      • shutdownExecutionService

        public static void shutdownExecutionService​(ExecutorService service,
                                                    long time,
                                                    TimeUnit timeUnit)
                                             throws InterruptedException
        Shuts down the executor. This operation puts the service into a state where every subsequent task submitted to the service will be rejected.
        Parameters:
        service - service to be shut down
        time - period of time to wait for the completion of the termination
        timeUnit - time duration granularity for the provided time
        Throws:
        InterruptedException