Package smile.util

Class MulticoreExecutor


  • public class MulticoreExecutor
    extends java.lang.Object
    Utility class to run tasks in a thread pool on multi-core systems.
    Author:
    Haifeng Li
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int getThreadPoolSize()
      Returns the number of threads in the thread pool.
      static <T> java.util.List<T> run​(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
      Executes the given tasks serially or parallel depending on the number of cores of the system.
      static void shutdown()
      Shutdown the thread pool.
      • Methods inherited from class java.lang.Object

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

      • getThreadPoolSize

        public static int getThreadPoolSize()
        Returns the number of threads in the thread pool. 0 and 1 mean no thread pool.
        Returns:
        the number of threads in the thread pool
      • run

        public static <T> java.util.List<T> run​(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
                                         throws java.lang.Exception
        Executes the given tasks serially or parallel depending on the number of cores of the system. Returns a list of result objects of each task. The results of this method are undefined if the given collection is modified while this operation is in progress.
        Parameters:
        tasks - the collection of tasks.
        Returns:
        a list of result objects in the same sequential order as produced by the iterator for the given task list.
        Throws:
        java.lang.Exception - if unable to compute a result.
      • shutdown

        public static void shutdown()
        Shutdown the thread pool.