Class SequentialTaskExecutor

  • All Implemented Interfaces:
    java.lang.AutoCloseable, TaskExecutor

    class SequentialTaskExecutor
    extends java.lang.Object
    implements TaskExecutor
    A TaskExecutor for single threaded execution.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      <T> void forEach​(java.util.List<? extends T> parameters, java.util.function.Consumer<? super T> task)
      Like TaskExecutor.runAll(List) but - instead of a list of tasks - it takes a list of parameters and a function that is called for each of the parameters.
      <T,​R>
      java.util.List<R>
      forEachApply​(java.util.List<? extends T> parameters, java.util.function.Function<? super T,​? extends R> task)
      Like TaskExecutor.forEach(List, Consumer) but collects the results.
      java.util.concurrent.ExecutorService getExecutorService()
      Get the underlying ExecutorService.
      static TaskExecutor getInstance()  
      int getParallelism()
      Get the number of threads that are used for execution.
      void runAll​(java.util.List<java.lang.Runnable> tasks)
      This method will execute the given list of tasks.
      int suggestNumberOfTasks()
      If there is a big task that could be split into sub tasks for parallelization, this method gives you a reasonable number of sub tasks.
      • Methods inherited from class java.lang.Object

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

      • executorService

        private final java.util.concurrent.ExecutorService executorService
    • Constructor Detail

      • SequentialTaskExecutor

        private SequentialTaskExecutor()
    • Method Detail

      • getExecutorService

        public java.util.concurrent.ExecutorService getExecutorService()
        Description copied from interface: TaskExecutor
        Get the underlying ExecutorService. This is not always a fully functional ExecutorService: Especially the methods ExecutorService.shutdown() and ExecutorService.awaitTermination(long, TimeUnit) must not be used.
        Specified by:
        getExecutorService in interface TaskExecutor
      • suggestNumberOfTasks

        public int suggestNumberOfTasks()
        Description copied from interface: TaskExecutor
        If there is a big task that could be split into sub tasks for parallelization, this method gives you a reasonable number of sub tasks.

        A single threaded TaskExecutor will return 1. A multi threaded TaskExecutor will usually return 4 times the number of threads.

        Specified by:
        suggestNumberOfTasks in interface TaskExecutor
      • getParallelism

        public int getParallelism()
        Description copied from interface: TaskExecutor
        Get the number of threads that are used for execution.
        Specified by:
        getParallelism in interface TaskExecutor
      • runAll

        public void runAll​(java.util.List<java.lang.Runnable> tasks)
        Description copied from interface: TaskExecutor
        This method will execute the given list of tasks. A single threaded TaskExecutor will execute the tasks one after the other. A multi threaded TaskExecutor will distribute the tasks to the threads. The method blocks until all tasks are completed.
        Specified by:
        runAll in interface TaskExecutor
      • forEach

        public <T> void forEach​(java.util.List<? extends T> parameters,
                                java.util.function.Consumer<? super T> task)
        Description copied from interface: TaskExecutor
        Like TaskExecutor.runAll(List) but - instead of a list of tasks - it takes a list of parameters and a function that is called for each of the parameters.
        Specified by:
        forEach in interface TaskExecutor
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface TaskExecutor