public class BoundedExecutor
extends java.lang.Object
Based on code from the book "Java Concurrency in Practice" by Brian Goetz
Constructor and Description |
---|
BoundedExecutor(java.util.concurrent.Executor exec,
int allowableNumberBeforeBlocking)
Constructs an Executor that allows Runnables to be executed using
multiple threads.
|
Modifier and Type | Method and Description |
---|---|
void |
execute(java.lang.Runnable command)
Executes the task by running the Runnable.run() method.
|
int |
spaceInQueue()
Returns how many items can still be added to the executor's queue.
|
public BoundedExecutor(java.util.concurrent.Executor exec, int allowableNumberBeforeBlocking)
exec
- The executor. Recommend using Executors.newFixedThreadPool()
to get a fixed thread pool.allowableNumberBeforeBlocking
- How many items that can be queued before execute() will block
if another Runnable is added. Includes both Runnables that are
currently running plus ones that have already been submitted
but are still queued up. The value needs to be at least as
large as the number of threads allowed by the Executor in
order for all threads to be usable simultaneously.public int spaceInQueue()
public void execute(java.lang.Runnable command) throws java.lang.InterruptedException
command
- For which run() is to be calledjava.lang.InterruptedException
- if this task cannot be accepted for execution.