Class ThreadPool


  • public class ThreadPool
    extends java.lang.Object
    Pool that executes each submitted task using one of possibly several pooled threads.

    Thread pools address two different problems: they usually provide improved performance when executing large numbers of asynchronous tasks, due to reduced per-task invocation overhead, and they provide a means of bounding and managing the resources, including threads, consumed when executing a collection of tasks.
    Since:
    TotalCross 4.3.9
    • Constructor Summary

      Constructors 
      Constructor Description
      ThreadPool​(int corePoolSize)
      Creates a new ThreadPool with the given initial parameters.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void execute​(java.lang.Runnable command)
      Executes the given task sometime in the future.
      protected void finalize()
      Invokes shutdown when this executor is no longer referenced and it has no threads.
      void shutdown()
      Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
      • Methods inherited from class java.lang.Object

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

      • ThreadPool

        public ThreadPool​(int corePoolSize)
        Creates a new ThreadPool with the given initial parameters.
        Parameters:
        corePoolSize - - the number of threads to keep in the pool, even if they are idle
    • Method Detail

      • execute

        public void execute​(java.lang.Runnable command)
                     throws java.lang.NullPointerException
        Executes the given task sometime in the future. The task may execute in a new thread or in an existing pooled thread. If the task cannot be submitted for execution, either because this executor has been shutdown or because its capacity has been reached, the task is handled by the current RejectedExecutionHandler.
        Parameters:
        command -
        Throws:
        java.lang.NullPointerException - if command is null
      • shutdown

        public void shutdown()
        Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Invokes shutdown when this executor is no longer referenced and it has no threads.
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable