Package io.inversion.utils
Class RestClient.Executor
java.lang.Object
io.inversion.utils.RestClient.Executor
- Enclosing class:
RestClient
An asynchronous thread pool task runner.
The number of threads in the pool will be expanded up to threadsMax and down to
thredsMin based on the size of of the queue. Up to queueMax tasks
can occupy the queue before caller will start to be blocked having to wait for queue space to
clear up.
You can completely disable asynchronous execution by setting threadsMax to zero.
That will ensure that tasks will always execute synchronously in the calling thread and will
be completed by the time submit returns.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected intThe thread pool will by dynamically expanded up to this max number of worker threads as the queue length grows.protected intThe thread pool will be dynamically contracted to this minimum number of worker threads as the queue length shrinks. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintintintsubmit(RunnableFuture task) Putstaskinto the queue to be run unlessthreadsMaxis less than one in which case the task is immediately run synchronously in stead of asynchronously.withQueueMax(int queueMax) withThreadsMax(int threadsMax) withThreadsMin(int threadsMin)
-
Field Details
-
threadsMin
protected int threadsMinThe thread pool will be dynamically contracted to this minimum number of worker threads as the queue length shrinks. -
threadsMax
protected int threadsMaxThe thread pool will by dynamically expanded up to this max number of worker threads as the queue length grows.If this number is less than 1, then tasks will be executed synchronously in the calling thread, not asynchronously.
-
queueMax
protected int queueMax
-
-
Constructor Details
-
Executor
public Executor()
-
-
Method Details
-
submit
-
submit
Putstaskinto the queue to be run unlessthreadsMaxis less than one in which case the task is immediately run synchronously in stead of asynchronously.- Parameters:
task- the task to run- Returns:
- the task submitted
-
getThreadsMin
public int getThreadsMin() -
withThreadsMin
-
getThreadsMax
public int getThreadsMax() -
withThreadsMax
-
getQueueMax
public int getQueueMax() -
withQueueMax
-