Class RestClient.Executor

java.lang.Object
io.inversion.utils.RestClient.Executor
Enclosing class:
RestClient

public static class RestClient.Executor extends Object
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 Details

    • threadsMin

      protected int threadsMin
      The thread pool will be dynamically contracted to this minimum number of worker threads as the queue length shrinks.
    • threadsMax

      protected int threadsMax
      The 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

      public Future submit(Runnable task)
    • submit

      public RunnableFuture submit(RunnableFuture task)
      Puts task into the queue to be run unless threadsMax is 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

      public RestClient.Executor withThreadsMin(int threadsMin)
    • getThreadsMax

      public int getThreadsMax()
    • withThreadsMax

      public RestClient.Executor withThreadsMax(int threadsMax)
    • getQueueMax

      public int getQueueMax()
    • withQueueMax

      public RestClient.Executor withQueueMax(int queueMax)