Package totalcross.util.concurrent
Class ThreadPool
- java.lang.Object
-
- totalcross.util.concurrent.ThreadPool
-
public class ThreadPool extends java.lang.ObjectPool 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 voidexecute(java.lang.Runnable command)Executes the given task sometime in the future.protected voidfinalize()Invokes shutdown when this executor is no longer referenced and it has no threads.voidshutdown()Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
-
-
-
Method Detail
-
execute
public void execute(java.lang.Runnable command) throws java.lang.NullPointerExceptionExecutes 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.ThrowableInvokes shutdown when this executor is no longer referenced and it has no threads.- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
-