Package org.elasticsearch.threadpool
Class ThreadPool
java.lang.Object
org.elasticsearch.threadpool.ThreadPool
- All Implemented Interfaces:
ReportingService<ThreadPoolInfo>,Scheduler
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classNested classes/interfaces inherited from interface org.elasticsearch.threadpool.Scheduler
Scheduler.Cancellable, Scheduler.ReschedulingRunnable, Scheduler.SafeScheduledThreadPoolExecutor, Scheduler.ScheduledCancellable -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the value of milliseconds since UNIX epoch.static booleanstatic booleanassertNotScheduleThread(String reason)booleanawaitTermination(long timeout, TimeUnit unit)builders()Get theExecutorServicewith the given name.generic()Get the genericExecutorService.info()longReturns a value of milliseconds that may be used for relative time calculations.longReturns a value of nanoseconds that may be used for relative time calculations.Schedules a one-shot command to run after a given delay.voidscheduleUnlessShuttingDown(org.elasticsearch.core.TimeValue delay, String executor, Runnable command)scheduleWithFixedDelay(Runnable command, org.elasticsearch.core.TimeValue interval, String executor)Schedules a periodic action that runs on scheduler thread.static intsearchThreadPoolSize(int allocatedProcessors)voidshutdown()voidstats()protected voidstatic booleanterminate(ExecutorService service, long timeout, TimeUnit timeUnit)Returnstrueif the given service was terminated successfully.static booleanterminate(ThreadPool pool, long timeout, TimeUnit timeUnit)Returnstrueif the given pool was terminated successfully.
-
Field Details
-
THREAD_POOL_TYPES
-
ESTIMATED_TIME_INTERVAL_SETTING
-
LATE_TIME_INTERVAL_WARN_THRESHOLD_SETTING
public static final Setting<org.elasticsearch.core.TimeValue> LATE_TIME_INTERVAL_WARN_THRESHOLD_SETTING -
SLOW_SCHEDULER_TASK_WARN_THRESHOLD_SETTING
public static final Setting<org.elasticsearch.core.TimeValue> SLOW_SCHEDULER_TASK_WARN_THRESHOLD_SETTING
-
-
Constructor Details
-
ThreadPool
-
-
Method Details
-
builders
-
relativeTimeInMillis
public long relativeTimeInMillis()Returns a value of milliseconds that may be used for relative time calculations. This method should only be used for calculating time deltas. For an epoch based timestamp, seeabsoluteTimeInMillis(). -
relativeTimeInNanos
public long relativeTimeInNanos()Returns a value of nanoseconds that may be used for relative time calculations. This method should only be used for calculating time deltas. For an epoch based timestamp, seeabsoluteTimeInMillis(). -
absoluteTimeInMillis
public long absoluteTimeInMillis()Returns the value of milliseconds since UNIX epoch. This method should only be used for exact date/time formatting. For calculating time deltas that should not suffer from negative deltas, which are possible with this method, seerelativeTimeInMillis(). -
info
- Specified by:
infoin interfaceReportingService<ThreadPoolInfo>
-
info
-
stats
-
generic
Get the genericExecutorService. This executor serviceExecutor.execute(Runnable)method will run theRunnableit is given in theThreadContextof the thread that queues it.Warning: this ExecutorService will not throw
RejectedExecutionExceptionif you submit a task while it shutdown. It will instead silently queue it and not run it. -
executor
Get theExecutorServicewith the given name. This executor service'sExecutor.execute(Runnable)method will run theRunnableit is given in theThreadContextof the thread that queues it.Warning: this ExecutorService might not throw
RejectedExecutionExceptionif you submit a task while it shutdown. It will instead silently queue it and not run it.- Parameters:
name- the name of the executor service to obtain- Throws:
IllegalArgumentException- if no executor service with the specified name exists
-
schedule
public Scheduler.ScheduledCancellable schedule(Runnable command, org.elasticsearch.core.TimeValue delay, String executor)Schedules a one-shot command to run after a given delay. The command is run in the context of the calling thread.- Specified by:
schedulein interfaceScheduler- Parameters:
command- the command to rundelay- 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.- Returns:
- a ScheduledFuture who's get will return when the task is has been added to its target thread pool and throw an exception if the task is canceled before it was added to its target thread pool. Once the task has been added to its target thread pool the ScheduledFuture will cannot interact with it.
- Throws:
EsRejectedExecutionException- if the task cannot be scheduled for execution
-
scheduleUnlessShuttingDown
-
scheduleWithFixedDelay
public Scheduler.Cancellable scheduleWithFixedDelay(Runnable command, org.elasticsearch.core.TimeValue interval, String executor)Description copied from interface:SchedulerSchedules a periodic action that runs on scheduler thread. Do not run blocking calls on the scheduler thread. Subclasses may allow to execute on a different executor, in which case blocking calls are allowed.- Specified by:
scheduleWithFixedDelayin interfaceScheduler- Parameters:
command- 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.- Returns:
- a
Scheduler.Cancellablethat can be used to cancel the subsequent runs of the command. If the command is running, it will not be interrupted.
-
stopCachedTimeThread
protected final void stopCachedTimeThread() -
shutdown
public void shutdown() -
shutdownNow
public void shutdownNow() -
awaitTermination
- Throws:
InterruptedException
-
scheduler
-
searchThreadPoolSize
public static int searchThreadPoolSize(int allocatedProcessors) -
terminate
Returnstrueif the given service was terminated successfully. If the termination timed out, the service isnullthis method will returnfalse. -
terminate
Returnstrueif the given pool was terminated successfully. If the termination timed out, the service isnullthis method will returnfalse. -
getThreadContext
-
assertNotScheduleThread
-
assertCurrentMethodIsNotCalledRecursively
public static boolean assertCurrentMethodIsNotCalledRecursively()
-