org.elasticsearch.threadpool
Interface ThreadPool

All Known Implementing Classes:
AbstractThreadPool, BlockingThreadPool, CachedThreadPool, ScalingThreadPool

public interface ThreadPool


Method Summary
 boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
           
 void execute(java.lang.Runnable command)
           
 int getActiveCount()
          Returns the approximate number of threads that are actively executing tasks.
 int getPoolSize()
          Returns the current number of threads in the pool.
 int getSchedulerActiveCount()
           
 int getSchedulerPoolSize()
           
 boolean isStarted()
          Returns true if the thread pool has started.
<V> java.util.concurrent.ScheduledFuture<V>
schedule(java.util.concurrent.Callable<V> callable, long delay, java.util.concurrent.TimeUnit unit)
          Creates and executes a ScheduledFuture that becomes enabled after the given delay.
 java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable command, long delay, java.util.concurrent.TimeUnit unit)
          Creates and executes a one-shot action that becomes enabled after the given delay.
 java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable command, TimeValue delay)
           
 java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate(java.lang.Runnable command, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
          Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on.
 java.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelay(java.lang.Runnable command, long initialDelay, long delay, java.util.concurrent.TimeUnit unit)
          Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.
 java.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelay(java.lang.Runnable command, TimeValue interval)
           
 void shutdown()
          Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
 void shutdownNow()
          Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.
<T> java.util.concurrent.Future<T>
submit(java.util.concurrent.Callable<T> task)
          Submits a value-returning task for execution and returns a Future representing the pending results of the task.
<T> java.util.concurrent.Future<T>
submit(java.util.concurrent.Callable<T> task, FutureListener<T> listener)
           
 java.util.concurrent.Future<?> submit(java.lang.Runnable task)
          Submits a Runnable task for execution and returns a Future representing that task.
 java.util.concurrent.Future<?> submit(java.lang.Runnable task, FutureListener<?> listener)
           
<T> java.util.concurrent.Future<T>
submit(java.lang.Runnable task, T result)
          Submits a Runnable task for execution and returns a Future representing that task.
<T> java.util.concurrent.Future<T>
submit(java.lang.Runnable task, T result, FutureListener<T> listener)
           
 

Method Detail

getPoolSize

int getPoolSize()
Returns the current number of threads in the pool.

Returns:
the number of threads

getActiveCount

int getActiveCount()
Returns the approximate number of threads that are actively executing tasks.

Returns:
the number of threads

getSchedulerPoolSize

int getSchedulerPoolSize()

getSchedulerActiveCount

int getSchedulerActiveCount()

isStarted

boolean isStarted()
Returns true if the thread pool has started.


shutdownNow

void shutdownNow()
Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via Thread.interrupt(), so any task that fails to respond to interrupts may never terminate.


shutdown

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.


awaitTermination

boolean awaitTermination(long timeout,
                         java.util.concurrent.TimeUnit unit)
                         throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

execute

void execute(java.lang.Runnable command)

submit

<T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
Submits a value-returning task for execution and returns a Future representing the pending results of the task. The Future's get method will return the task's result upon successful completion.

If you would like to immediately block waiting for a task, you can use constructions of the form result = exec.submit(aCallable).get();

Note: The Executors class includes a set of methods that can convert some other common closure-like objects, for example, PrivilegedAction to Callable form so they can be submitted.

Parameters:
task - the task to submit
Returns:
a Future representing pending completion of the task
Throws:
java.util.concurrent.RejectedExecutionException - if the task cannot be scheduled for execution
java.lang.NullPointerException - if the task is null

submit

<T> java.util.concurrent.Future<T> submit(java.lang.Runnable task,
                                          T result)
Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return the given result upon successful completion.

Parameters:
task - the task to submit
result - the result to return
Returns:
a Future representing pending completion of the task
Throws:
java.util.concurrent.RejectedExecutionException - if the task cannot be scheduled for execution
java.lang.NullPointerException - if the task is null

submit

java.util.concurrent.Future<?> submit(java.lang.Runnable task)
Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return null upon successful completion.

Parameters:
task - the task to submit
Returns:
a Future representing pending completion of the task
Throws:
java.util.concurrent.RejectedExecutionException - if the task cannot be scheduled for execution
java.lang.NullPointerException - if the task is null

submit

<T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task,
                                          FutureListener<T> listener)

submit

<T> java.util.concurrent.Future<T> submit(java.lang.Runnable task,
                                          T result,
                                          FutureListener<T> listener)

submit

java.util.concurrent.Future<?> submit(java.lang.Runnable task,
                                      FutureListener<?> listener)

schedule

java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable command,
                                                 long delay,
                                                 java.util.concurrent.TimeUnit unit)
Creates and executes a one-shot action that becomes enabled after the given delay.

Parameters:
command - the task to execute
delay - the time from now to delay execution
unit - the time unit of the delay parameter
Returns:
a ScheduledFuture representing pending completion of the task and whose get() method will return null upon completion
Throws:
java.util.concurrent.RejectedExecutionException - if the task cannot be scheduled for execution
java.lang.NullPointerException - if command is null

schedule

<V> java.util.concurrent.ScheduledFuture<V> schedule(java.util.concurrent.Callable<V> callable,
                                                     long delay,
                                                     java.util.concurrent.TimeUnit unit)
Creates and executes a ScheduledFuture that becomes enabled after the given delay.

Parameters:
callable - the function to execute
delay - the time from now to delay execution
unit - the time unit of the delay parameter
Returns:
a ScheduledFuture that can be used to extract result or cancel
Throws:
java.util.concurrent.RejectedExecutionException - if the task cannot be scheduled for execution
java.lang.NullPointerException - if callable is null

scheduleAtFixedRate

java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate(java.lang.Runnable command,
                                                            long initialDelay,
                                                            long period,
                                                            java.util.concurrent.TimeUnit unit)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor. If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.

Parameters:
command - the task to execute
initialDelay - the time to delay first execution
period - the period between successive executions
unit - the time unit of the initialDelay and period parameters
Returns:
a ScheduledFuture representing pending completion of the task, and whose get() method will throw an exception upon cancellation
Throws:
java.util.concurrent.RejectedExecutionException - if the task cannot be scheduled for execution
java.lang.NullPointerException - if command is null
java.lang.IllegalArgumentException - if period less than or equal to zero

scheduleWithFixedDelay

java.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelay(java.lang.Runnable command,
                                                               long initialDelay,
                                                               long delay,
                                                               java.util.concurrent.TimeUnit unit)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor.

Parameters:
command - the task to execute
initialDelay - the time to delay first execution
delay - the delay between the termination of one execution and the commencement of the next
unit - the time unit of the initialDelay and delay parameters
Returns:
a ScheduledFuture representing pending completion of the task, and whose get() method will throw an exception upon cancellation
Throws:
java.util.concurrent.RejectedExecutionException - if the task cannot be scheduled for execution
java.lang.NullPointerException - if command is null
java.lang.IllegalArgumentException - if delay less than or equal to zero

schedule

java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable command,
                                                 TimeValue delay)

scheduleWithFixedDelay

java.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelay(java.lang.Runnable command,
                                                               TimeValue interval)