public class ThreadPool extends AbstractComponent implements Scheduler, java.io.Closeable
| Modifier and Type | Class and Description |
|---|---|
static class |
ThreadPool.Info |
static class |
ThreadPool.Names |
static class |
ThreadPool.ThreadPoolType |
Scheduler.Cancellable, Scheduler.ReschedulingRunnable| Modifier and Type | Field and Description |
|---|---|
static Setting<TimeValue> |
ESTIMATED_TIME_INTERVAL_SETTING |
static java.util.Map<java.lang.String,ThreadPool.ThreadPoolType> |
THREAD_POOL_TYPES |
deprecationLogger, logger, settings| Constructor and Description |
|---|
ThreadPool(Settings settings,
ExecutorBuilder<?>... customBuilders) |
| Modifier and Type | Method and Description |
|---|---|
long |
absoluteTimeInMillis()
Returns the value of milliseconds since UNIX epoch.
|
static boolean |
assertNotScheduleThread(java.lang.String reason) |
boolean |
awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit) |
java.util.Collection<ExecutorBuilder> |
builders() |
void |
close() |
org.apache.lucene.util.Counter |
estimatedTimeInMillisCounter() |
java.util.concurrent.ExecutorService |
executor(java.lang.String name)
Get the
ExecutorService with the given name. |
java.util.concurrent.ExecutorService |
generic()
Get the generic
ExecutorService. |
ThreadContext |
getThreadContext() |
ThreadPoolInfo |
info() |
ThreadPool.Info |
info(java.lang.String name) |
java.lang.Runnable |
preserveContext(java.lang.Runnable command)
Does nothing by default but can be used by subclasses to save the current thread context and wraps the command in a Runnable
that restores that context before running the command.
|
long |
relativeTimeInMillis()
Returns a value of milliseconds that may be used for relative time calculations.
|
java.util.concurrent.ScheduledFuture<?> |
schedule(TimeValue delay,
java.lang.String executor,
java.lang.Runnable command)
Schedules a one-shot command to run after a given delay.
|
java.util.concurrent.ScheduledExecutorService |
scheduler() |
Scheduler.Cancellable |
scheduleWithFixedDelay(java.lang.Runnable command,
TimeValue interval,
java.lang.String executor)
Schedules a periodic action that runs on scheduler thread.
|
static int |
searchThreadPoolSize(int availableProcessors) |
void |
shutdown() |
void |
shutdownNow() |
ThreadPoolStats |
stats() |
static boolean |
terminate(java.util.concurrent.ExecutorService service,
long timeout,
java.util.concurrent.TimeUnit timeUnit)
Returns
true if the given service was terminated successfully. |
static boolean |
terminate(ThreadPool pool,
long timeout,
java.util.concurrent.TimeUnit timeUnit)
Returns
true if the given pool was terminated successfully. |
logDeprecatedSetting, logRemovedSetting, nodeNameclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitawaitTermination, initScheduler, terminatepublic static final java.util.Map<java.lang.String,ThreadPool.ThreadPoolType> THREAD_POOL_TYPES
public ThreadPool(Settings settings, ExecutorBuilder<?>... customBuilders)
public java.util.Collection<ExecutorBuilder> builders()
public long relativeTimeInMillis()
absoluteTimeInMillis().public long absoluteTimeInMillis()
relativeTimeInMillis().public org.apache.lucene.util.Counter estimatedTimeInMillisCounter()
public ThreadPoolInfo info()
public ThreadPool.Info info(java.lang.String name)
public ThreadPoolStats stats()
public java.util.concurrent.ExecutorService generic()
ExecutorService. This executor service
Executor.execute(Runnable) method will run the Runnable it is given in the
ThreadContext of the thread that queues it.
Warning: this ExecutorService will not throw RejectedExecutionException
if you submit a task while it shutdown. It will instead silently queue it and not run it.
public java.util.concurrent.ExecutorService executor(java.lang.String name)
ExecutorService with the given name. This executor service's
Executor.execute(Runnable) method will run the Runnable it is given in the
ThreadContext of the thread that queues it.
Warning: this ExecutorService might not throw RejectedExecutionException
if you submit a task while it shutdown. It will instead silently queue it and not run it.
name - the name of the executor service to obtainjava.lang.IllegalArgumentException - if no executor service with the specified name existspublic java.util.concurrent.ScheduledFuture<?> schedule(TimeValue delay, java.lang.String executor, java.lang.Runnable command)
threadPool.getThreadContext().preserveContext on the runnable before passing
it to this method.schedule in interface Schedulerdelay - delay before the task executesexecutor - the name of the thread pool on which to execute this task. SAME means "execute on the scheduler thread" which changes the
meaning of the ScheduledFuture returned by this method. In that case the ScheduledFuture will complete only when the command
completes.command - the command to runEsRejectedExecutionException - if the task cannot be scheduled for executionpublic Scheduler.Cancellable scheduleWithFixedDelay(java.lang.Runnable command, TimeValue interval, java.lang.String executor)
SchedulerscheduleWithFixedDelay in interface Schedulercommand - the action to takeinterval - the delay intervalexecutor - the name of the executor that has to execute this task. Ignored in the default implementation but can be used
by subclasses that support multiple executors.Scheduler.Cancellable that can be used to cancel the subsequent runs of the command. If the command is running, it will
not be interrupted.public java.lang.Runnable preserveContext(java.lang.Runnable command)
SchedulerpreserveContext in interface Schedulerpublic void shutdown()
public void shutdownNow()
public boolean awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic java.util.concurrent.ScheduledExecutorService scheduler()
public static int searchThreadPoolSize(int availableProcessors)
public static boolean terminate(java.util.concurrent.ExecutorService service,
long timeout,
java.util.concurrent.TimeUnit timeUnit)
true if the given service was terminated successfully. If the termination timed out,
the service is null this method will return false.public static boolean terminate(ThreadPool pool, long timeout, java.util.concurrent.TimeUnit timeUnit)
true if the given pool was terminated successfully. If the termination timed out,
the service is null this method will return false.public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionpublic ThreadContext getThreadContext()
public static boolean assertNotScheduleThread(java.lang.String reason)