Package io.github.connellite.concurrent
Class ThreadPool
java.lang.Object
io.github.connellite.concurrent.ThreadPool
- All Implemented Interfaces:
AutoCloseable
-
Constructor Summary
ConstructorsConstructorDescriptionThreadPool(int threads) The constructor just launches some amount of workers -
Method Summary
-
Constructor Details
-
ThreadPool
public ThreadPool(int threads) The constructor just launches some amount of workers- Parameters:
threads- number of threads- Throws:
IllegalStateException- if number of threads is less than or equal to 0
-
-
Method Details
-
enqueue
Add new work item to the pool- Parameters:
task- work item- Throws:
IllegalStateException- if stopped ThreadPool
-
enqueue
Add new work item to the pool- Type Parameters:
T- The result type returned by this Future's get method- Parameters:
task- work item- Returns:
Future<T>- Throws:
IllegalStateException- if stopped ThreadPool
-
close
public void close()Join all threads, stop ThreadPool- Specified by:
closein interfaceAutoCloseable
-