Class PrioritySchedulerStatisticTracker
- java.lang.Object
-
- org.threadly.concurrent.AbstractSubmitterExecutor
-
- org.threadly.concurrent.AbstractSubmitterScheduler
-
- org.threadly.concurrent.AbstractPriorityScheduler
-
- org.threadly.concurrent.PriorityScheduler
-
- org.threadly.concurrent.statistics.PrioritySchedulerStatisticTracker
-
- All Implemented Interfaces:
java.util.concurrent.Executor
,PrioritySchedulerService
,SchedulerService
,StatisticExecutor
,StatisticPriorityScheduler
,SubmitterExecutor
,SubmitterScheduler
public class PrioritySchedulerStatisticTracker extends PriorityScheduler implements StatisticPriorityScheduler
An implementation ofPriorityScheduler
which tracks run and usage statistics. This is designed for testing and troubleshooting. It has a little more overhead from the normalPriorityScheduler
.It helps give insight in how long tasks are running, how well the thread pool is being utilized, as well as execution frequency.
- Since:
- 4.5.0 (since 1.0.0 at org.threadly.concurrent)
-
-
Constructor Summary
Constructors Constructor Description PrioritySchedulerStatisticTracker(int poolSize)
Constructs a new thread pool, though no threads will be started till it accepts it's first request.PrioritySchedulerStatisticTracker(int poolSize, boolean useDaemonThreads)
Constructs a new thread pool, though no threads will be started till it accepts it's first request.PrioritySchedulerStatisticTracker(int poolSize, boolean useDaemonThreads, int maxStatisticWindowSize, boolean accurateTime)
Constructs a new thread pool, though no threads will be started till it accepts it's first request.PrioritySchedulerStatisticTracker(int poolSize, int maxStatisticWindowSize, boolean accurateTime)
Constructs a new thread pool, though no threads will be started till it accepts it's first request.PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs)
Constructs a new thread pool, though no threads will be started till it accepts it's first request.PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, boolean useDaemonThreads)
Constructs a new thread pool, though no threads will be started till it accepts it's first request.PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, boolean useDaemonThreads, int maxStatisticWindowSize, boolean accurateTime)
Constructs a new thread pool, though no threads will be started till it accepts it's first request.PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, boolean stavableStartsThreads, java.util.concurrent.ThreadFactory threadFactory)
Constructs a new thread pool, though no threads will be started till it accepts it's first request.PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, boolean stavableStartsThreads, java.util.concurrent.ThreadFactory threadFactory, int maxStatisticWindowSize, boolean accurateTime)
Constructs a new thread pool, though no threads will be started till it accepts it's first request.PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, int maxStatisticWindowSize, boolean accurateTime)
Constructs a new thread pool, though no threads will be started till it accepts it's first request.PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, java.util.concurrent.ThreadFactory threadFactory)
Constructs a new thread pool, though no threads will be started till it accepts it's first request.PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, java.util.concurrent.ThreadFactory threadFactory, int maxStatisticWindowSize, boolean accurateTime)
Constructs a new thread pool, though no threads will be started till it accepts it's first request.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
getAverageExecutionDelay()
This reports the rolling average delay from when a task was expected to run, till when the executor actually started the task.double
getAverageExecutionDelay(TaskPriority priority)
Gets the average delay from when the task is ready, to when it is actually executed.double
getAverageExecutionDuration()
Get the average duration that tasks submitted through this executor have spent executing.double
getAverageExecutionDuration(TaskPriority priority)
Get the average duration that tasks submitted through this executor have spent executing.java.util.Map<java.lang.Double,java.lang.Long>
getExecutionDelayPercentiles(double... percentiles)
Gets percentile values for execution delays.java.util.Map<java.lang.Double,java.lang.Long>
getExecutionDelayPercentiles(TaskPriority priority, double... percentiles)
Gets percentile values for execution delays.java.util.List<java.lang.Long>
getExecutionDelaySamples()
Get raw sample data for task execution delays.java.util.List<java.lang.Long>
getExecutionDelaySamples(TaskPriority priority)
Call to get a list of all currently recorded times for execution delays.java.util.Map<java.lang.Double,java.lang.Long>
getExecutionDurationPercentiles(double... percentiles)
Gets percentile values for execution duration.java.util.Map<java.lang.Double,java.lang.Long>
getExecutionDurationPercentiles(TaskPriority priority, double... percentiles)
Gets percentile values for execution duration.java.util.List<java.lang.Long>
getExecutionDurationSamples()
Get raw sample data for task run durations.java.util.List<java.lang.Long>
getExecutionDurationSamples(TaskPriority priority)
Get raw sample data for task run durations.java.util.List<Pair<java.lang.Runnable,java.lang.StackTraceElement[]>>
getLongRunningTasks(long durationLimitMillis)
Call to get a list of runnables and stack traces from tasks which have been actively executing for a longer duration than the one provided.int
getLongRunningTasksQty(long durationLimitMillis)
Call to return the number of tasks which have been running longer than the provided duration in milliseconds.long
getTotalExecutionCount()
Call to get the total quantity of tasks this executor has handled.long
getTotalExecutionCount(TaskPriority priority)
Call to get the total quantity of tasks this executor has handled for a specific priority.void
resetCollectedStats()
Clears all collected rolling statistics.void
scheduleAtFixedRate(java.lang.Runnable task, long initialDelay, long period, TaskPriority priority)
Schedule a fixed rate recurring task to run.void
scheduleWithFixedDelay(java.lang.Runnable task, long initialDelay, long recurringDelay, TaskPriority priority)
Schedule a fixed delay recurring task to run.java.util.List<java.lang.Runnable>
shutdownNow()
Stops any new tasks from being able to be executed and removes workers from the pool.-
Methods inherited from class org.threadly.concurrent.PriorityScheduler
adjustPoolSize, awaitTermination, awaitTermination, getActiveTaskCount, getCurrentPoolSize, getMaxPoolSize, getQueuedTaskCount, getQueuedTaskCount, isShutdown, prestartAllThreads, setPoolSize, shutdown
-
Methods inherited from class org.threadly.concurrent.AbstractPriorityScheduler
execute, getDefaultPriority, getMaxWaitForLowPriority, getWaitingForExecutionTaskCount, getWaitingForExecutionTaskCount, remove, remove, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, setMaxWaitForLowPriority, submit, submit, submitScheduled, submitScheduled
-
Methods inherited from class org.threadly.concurrent.AbstractSubmitterScheduler
schedule, submitScheduled, submitScheduled
-
Methods inherited from class org.threadly.concurrent.AbstractSubmitterExecutor
execute, submit, submit
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.threadly.concurrent.PrioritySchedulerService
execute, getDefaultPriority, getMaxWaitForLowPriority, getQueuedTaskCount, getWaitingForExecutionTaskCount, schedule, submit, submit, submit, submitScheduled, submitScheduled, submitScheduled
-
Methods inherited from interface org.threadly.concurrent.SchedulerService
getActiveTaskCount, getQueuedTaskCount, getWaitingForExecutionTaskCount, isShutdown, remove, remove
-
Methods inherited from interface org.threadly.concurrent.statistics.StatisticExecutor
getQueuedTaskCount
-
Methods inherited from interface org.threadly.concurrent.SubmitterExecutor
submit, submit, submit
-
Methods inherited from interface org.threadly.concurrent.SubmitterScheduler
schedule, scheduleAtFixedRate, scheduleWithFixedDelay, submitScheduled, submitScheduled, submitScheduled
-
-
-
-
Constructor Detail
-
PrioritySchedulerStatisticTracker
public PrioritySchedulerStatisticTracker(int poolSize)
Constructs a new thread pool, though no threads will be started till it accepts it's first request. This constructs a default priority of high (which makes sense for most use cases). It also defaults low priority worker wait as 500ms. It also defaults to all newly created threads being daemon threads.This defaults to inaccurate time. Meaning that durations and delays may under report (but NEVER OVER what they actually were). This has the least performance impact. If you want more accurate time consider using one of the constructors that accepts a boolean for accurate time.
- Parameters:
poolSize
- Thread pool size that should be maintained
-
PrioritySchedulerStatisticTracker
public PrioritySchedulerStatisticTracker(int poolSize, boolean useDaemonThreads)
Constructs a new thread pool, though no threads will be started till it accepts it's first request. This constructs a default priority of high (which makes sense for most use cases). It also defaults low priority worker wait as 500ms.This defaults to inaccurate time. Meaning that durations and delays may under report (but NEVER OVER what they actually were). This has the least performance impact. If you want more accurate time consider using one of the constructors that accepts a boolean for accurate time.
- Parameters:
poolSize
- Thread pool size that should be maintaineduseDaemonThreads
-true
if newly created threads should be daemon
-
PrioritySchedulerStatisticTracker
public PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs)
Constructs a new thread pool, though no threads will be started till it accepts it's first request. This provides the extra parameters to tune what tasks submitted without a priority will be scheduled as. As well as the maximum wait for low priority tasks. The longer low priority tasks wait for a worker, the less chance they will have to create a thread. But it also makes low priority tasks execution time less predictable.This defaults to inaccurate time. Meaning that durations and delays may under report (but NEVER OVER what they actually were). This has the least performance impact. If you want more accurate time consider using one of the constructors that accepts a boolean for accurate time.
- Parameters:
poolSize
- Thread pool size that should be maintaineddefaultPriority
- priority to give tasks which do not specify itmaxWaitForLowPriorityInMs
- time low priority tasks wait for a worker
-
PrioritySchedulerStatisticTracker
public PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, boolean useDaemonThreads)
Constructs a new thread pool, though no threads will be started till it accepts it's first request. This provides the extra parameters to tune what tasks submitted without a priority will be scheduled as. As well as the maximum wait for low priority tasks. The longer low priority tasks wait for a worker, the less chance they will have to create a thread. But it also makes low priority tasks execution time less predictable.This defaults to inaccurate time. Meaning that durations and delays may under report (but NEVER OVER what they actually were). This has the least performance impact. If you want more accurate time consider using one of the constructors that accepts a boolean for accurate time.
- Parameters:
poolSize
- Thread pool size that should be maintaineddefaultPriority
- priority to give tasks which do not specify itmaxWaitForLowPriorityInMs
- time low priority tasks wait for a workeruseDaemonThreads
-true
if newly created threads should be daemon
-
PrioritySchedulerStatisticTracker
public PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, java.util.concurrent.ThreadFactory threadFactory)
Constructs a new thread pool, though no threads will be started till it accepts it's first request. This provides the extra parameters to tune what tasks submitted without a priority will be scheduled as. As well as the maximum wait for low priority tasks. The longer low priority tasks wait for a worker, the less chance they will have to create a thread. But it also makes low priority tasks execution time less predictable. This will by default start threads forTaskPriority.Low
and higher priority tasks.This defaults to inaccurate time. Meaning that durations and delays may under report (but NEVER OVER what they actually were). This has the least performance impact. If you want more accurate time consider using one of the constructors that accepts a boolean for accurate time.
- Parameters:
poolSize
- Thread pool size that should be maintaineddefaultPriority
- priority to give tasks which do not specify itmaxWaitForLowPriorityInMs
- time low priority tasks wait for a workerthreadFactory
- thread factory for producing new threads within executor
-
PrioritySchedulerStatisticTracker
public PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, boolean stavableStartsThreads, java.util.concurrent.ThreadFactory threadFactory)
Constructs a new thread pool, though no threads will be started till it accepts it's first request. This provides the extra parameters to tune what tasks submitted without a priority will be scheduled as. As well as the maximum wait for low priority tasks. The longer low priority tasks wait for a worker, the less chance they will have to create a thread. But it also makes low priority tasks execution time less predictable.This defaults to inaccurate time. Meaning that durations and delays may under report (but NEVER OVER what they actually were). This has the least performance impact. If you want more accurate time consider using one of the constructors that accepts a boolean for accurate time.
- Parameters:
poolSize
- Thread pool size that should be maintaineddefaultPriority
- priority to give tasks which do not specify itmaxWaitForLowPriorityInMs
- time low priority tasks wait for a workerstavableStartsThreads
-true
to have TaskPriority.Starvable tasks start new threadsthreadFactory
- thread factory for producing new threads within executor
-
PrioritySchedulerStatisticTracker
public PrioritySchedulerStatisticTracker(int poolSize, int maxStatisticWindowSize, boolean accurateTime)
Constructs a new thread pool, though no threads will be started till it accepts it's first request. This constructs a default priority of high (which makes sense for most use cases). It also defaults low priority worker wait as 500ms. It also defaults to all newly created threads being daemon threads.- Parameters:
poolSize
- Thread pool size that should be maintainedmaxStatisticWindowSize
- maximum number of samples to keep internallyaccurateTime
-true
to ensure that delays and durations are not under reported
-
PrioritySchedulerStatisticTracker
public PrioritySchedulerStatisticTracker(int poolSize, boolean useDaemonThreads, int maxStatisticWindowSize, boolean accurateTime)
Constructs a new thread pool, though no threads will be started till it accepts it's first request. This constructs a default priority of high (which makes sense for most use cases). It also defaults low priority worker wait as 500ms.- Parameters:
poolSize
- Thread pool size that should be maintaineduseDaemonThreads
-true
if newly created threads should be daemonmaxStatisticWindowSize
- maximum number of samples to keep internallyaccurateTime
-true
to ensure that delays and durations are not under reported
-
PrioritySchedulerStatisticTracker
public PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, int maxStatisticWindowSize, boolean accurateTime)
Constructs a new thread pool, though no threads will be started till it accepts it's first request. This provides the extra parameters to tune what tasks submitted without a priority will be scheduled as. As well as the maximum wait for low priority tasks. The longer low priority tasks wait for a worker, the less chance they will have to create a thread. But it also makes low priority tasks execution time less predictable.- Parameters:
poolSize
- Thread pool size that should be maintaineddefaultPriority
- priority to give tasks which do not specify itmaxWaitForLowPriorityInMs
- time low priority tasks wait for a workermaxStatisticWindowSize
- maximum number of samples to keep internallyaccurateTime
-true
to ensure that delays and durations are not under reported
-
PrioritySchedulerStatisticTracker
public PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, boolean useDaemonThreads, int maxStatisticWindowSize, boolean accurateTime)
Constructs a new thread pool, though no threads will be started till it accepts it's first request. This provides the extra parameters to tune what tasks submitted without a priority will be scheduled as. As well as the maximum wait for low priority tasks. The longer low priority tasks wait for a worker, the less chance they will have to create a thread. But it also makes low priority tasks execution time less predictable. This will by default start threads forTaskPriority.Low
and higher priority tasks.- Parameters:
poolSize
- Thread pool size that should be maintaineddefaultPriority
- priority to give tasks which do not specify itmaxWaitForLowPriorityInMs
- time low priority tasks wait for a workeruseDaemonThreads
-true
if newly created threads should be daemonmaxStatisticWindowSize
- maximum number of samples to keep internallyaccurateTime
-true
to ensure that delays and durations are not under reported
-
PrioritySchedulerStatisticTracker
public PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, java.util.concurrent.ThreadFactory threadFactory, int maxStatisticWindowSize, boolean accurateTime)
Constructs a new thread pool, though no threads will be started till it accepts it's first request. This provides the extra parameters to tune what tasks submitted without a priority will be scheduled as. As well as the maximum wait for low priority tasks. The longer low priority tasks wait for a worker, the less chance they will have to create a thread. But it also makes low priority tasks execution time less predictable. This will by default start threads forTaskPriority.Low
and higher priority tasks.- Parameters:
poolSize
- Thread pool size that should be maintaineddefaultPriority
- priority to give tasks which do not specify itmaxWaitForLowPriorityInMs
- time low priority tasks wait for a workerthreadFactory
- thread factory for producing new threads within executormaxStatisticWindowSize
- maximum number of samples to keep internallyaccurateTime
-true
to ensure that delays and durations are not under reported
-
PrioritySchedulerStatisticTracker
public PrioritySchedulerStatisticTracker(int poolSize, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, boolean stavableStartsThreads, java.util.concurrent.ThreadFactory threadFactory, int maxStatisticWindowSize, boolean accurateTime)
Constructs a new thread pool, though no threads will be started till it accepts it's first request. This provides the extra parameters to tune what tasks submitted without a priority will be scheduled as. As well as the maximum wait for low priority tasks. The longer low priority tasks wait for a worker, the less chance they will have to create a thread. But it also makes low priority tasks execution time less predictable.- Parameters:
poolSize
- Thread pool size that should be maintaineddefaultPriority
- priority to give tasks which do not specify itmaxWaitForLowPriorityInMs
- time low priority tasks wait for a workerstavableStartsThreads
-true
to have TaskPriority.Starvable tasks start new threadsthreadFactory
- thread factory for producing new threads within executormaxStatisticWindowSize
- maximum number of samples to keep internallyaccurateTime
-true
to ensure that delays and durations are not under reported
-
-
Method Detail
-
shutdownNow
public java.util.List<java.lang.Runnable> shutdownNow()
Description copied from class:PriorityScheduler
Stops any new tasks from being able to be executed and removes workers from the pool.This implementation refuses new submissions after this call. And will NOT interrupt any tasks which are currently running. However any tasks which are waiting in queue to be run (but have not started yet), will not be run. Those waiting tasks will be removed, and as workers finish with their current tasks the threads will be joined.
- Overrides:
shutdownNow
in classPriorityScheduler
- Returns:
- List of runnables which were waiting to execute
-
scheduleWithFixedDelay
public void scheduleWithFixedDelay(java.lang.Runnable task, long initialDelay, long recurringDelay, TaskPriority priority)
Description copied from interface:PrioritySchedulerService
Schedule a fixed delay recurring task to run. The recurring delay time will be from the point where execution has finished. So the execution frequency is therecurringDelay + runtime
for the provided task.Unlike
ScheduledExecutorService
if the task throws an exception, subsequent executions are NOT suppressed or prevented. So if the task throws an exception on every run, the task will continue to be executed at the provided recurring delay (possibly throwing an exception on each execution).- Specified by:
scheduleWithFixedDelay
in interfacePrioritySchedulerService
- Overrides:
scheduleWithFixedDelay
in classPriorityScheduler
- Parameters:
task
- runnable to be executedinitialDelay
- delay in milliseconds until first runrecurringDelay
- delay in milliseconds for running task after last finishpriority
- priority for task to get available thread to run on
-
scheduleAtFixedRate
public void scheduleAtFixedRate(java.lang.Runnable task, long initialDelay, long period, TaskPriority priority)
Description copied from interface:PrioritySchedulerService
Schedule a fixed rate recurring task to run. The recurring delay will be the same, regardless of how long task execution takes. A given runnable will not run concurrently (unless it is submitted to the scheduler multiple times). Instead of execution takes longer than the period, the next run will occur immediately (given thread availability in the pool).Unlike
ScheduledExecutorService
if the task throws an exception, subsequent executions are NOT suppressed or prevented. So if the task throws an exception on every run, the task will continue to be executed at the provided recurring delay (possibly throwing an exception on each execution).- Specified by:
scheduleAtFixedRate
in interfacePrioritySchedulerService
- Overrides:
scheduleAtFixedRate
in classPriorityScheduler
- Parameters:
task
- runnable to be executedinitialDelay
- delay in milliseconds until first runperiod
- amount of time in milliseconds between the start of recurring executionspriority
- priority for task to get available thread to run on
-
getExecutionDelaySamples
public java.util.List<java.lang.Long> getExecutionDelaySamples()
Description copied from interface:StatisticPriorityScheduler
Get raw sample data for task execution delays. This raw data can be used for more advanced statistics which are not provided in this library. These can also be fed into utilities inStatisticsUtils
for additional statistics.The returned result set includes all priorities. If you want durations for a specific priority use
StatisticPriorityScheduler.getExecutionDelaySamples(TaskPriority)
.- Specified by:
getExecutionDelaySamples
in interfaceStatisticExecutor
- Specified by:
getExecutionDelaySamples
in interfaceStatisticPriorityScheduler
- Returns:
- A list of delay times in milliseconds before a task was executed
-
getExecutionDelaySamples
public java.util.List<java.lang.Long> getExecutionDelaySamples(TaskPriority priority)
Description copied from interface:StatisticPriorityScheduler
Call to get a list of all currently recorded times for execution delays. This is the window used for the rolling average forStatisticPriorityScheduler.getAverageExecutionDelay(TaskPriority)
. This call allows for more complex statistics (ie looking for outliers, etc).- Specified by:
getExecutionDelaySamples
in interfaceStatisticPriorityScheduler
- Parameters:
priority
- Task priority to provide samples for- Returns:
- list which represents execution delay samples
-
getAverageExecutionDelay
public double getAverageExecutionDelay()
Description copied from interface:StatisticPriorityScheduler
This reports the rolling average delay from when a task was expected to run, till when the executor actually started the task. This will return-1
if no samples have been collected yet. This call averages over all priority types, if you want the delay for a specific priority useStatisticPriorityScheduler.getAverageExecutionDelay(TaskPriority)
.- Specified by:
getAverageExecutionDelay
in interfaceStatisticExecutor
- Specified by:
getAverageExecutionDelay
in interfaceStatisticPriorityScheduler
- Returns:
- Average delay for tasks to be executed in milliseconds
-
getAverageExecutionDelay
public double getAverageExecutionDelay(TaskPriority priority)
Description copied from interface:StatisticPriorityScheduler
Gets the average delay from when the task is ready, to when it is actually executed. This will only inspect the times for a specific priority.- Specified by:
getAverageExecutionDelay
in interfaceStatisticPriorityScheduler
- Parameters:
priority
- Specific task priority which statistics should be calculated against- Returns:
- Average delay for tasks to be executed in milliseconds
-
getExecutionDelayPercentiles
public java.util.Map<java.lang.Double,java.lang.Long> getExecutionDelayPercentiles(double... percentiles)
Description copied from interface:StatisticPriorityScheduler
Gets percentile values for execution delays. This function accepts any decimal percentile between zero and one hundred.The returned map's keys correspond exactly to the percentiles provided. Iterating over the returned map will iterate in order of the requested percentiles as well.
These percentiles are across all priorities combined into the same data set. If you want percentiles for a specific priority use
StatisticPriorityScheduler.getExecutionDelayPercentiles(TaskPriority, double...)
.- Specified by:
getExecutionDelayPercentiles
in interfaceStatisticExecutor
- Specified by:
getExecutionDelayPercentiles
in interfaceStatisticPriorityScheduler
- Parameters:
percentiles
- Percentiles requested, any decimal values between 0 and 100 (inclusive)- Returns:
- Map with keys being the percentiles requested, value being the execution delay in milliseconds
-
getExecutionDelayPercentiles
public java.util.Map<java.lang.Double,java.lang.Long> getExecutionDelayPercentiles(TaskPriority priority, double... percentiles)
Description copied from interface:StatisticPriorityScheduler
Gets percentile values for execution delays. This function accepts any decimal percentile between zero and one hundred.The returned map's keys correspond exactly to the percentiles provided. Iterating over the returned map will iterate in order of the requested percentiles as well.
- Specified by:
getExecutionDelayPercentiles
in interfaceStatisticPriorityScheduler
- Parameters:
priority
- Specific task priority which statistics should be calculated againstpercentiles
- Percentiles requested, any decimal values between 0 and 100 (inclusive)- Returns:
- Map with keys being the percentiles requested, value being the execution delay in milliseconds
-
getExecutionDurationSamples
public java.util.List<java.lang.Long> getExecutionDurationSamples()
Description copied from interface:StatisticPriorityScheduler
Get raw sample data for task run durations. This raw data can be used for more advanced statistics which are not provided in this library. These can also be fed into utilities inStatisticsUtils
for additional statistics.The returned result set includes all priorities. If you want durations for a specific priority use
StatisticPriorityScheduler.getExecutionDurationSamples(TaskPriority)
.- Specified by:
getExecutionDurationSamples
in interfaceStatisticExecutor
- Specified by:
getExecutionDurationSamples
in interfaceStatisticPriorityScheduler
- Returns:
- A list of task durations in milliseconds
-
getExecutionDurationSamples
public java.util.List<java.lang.Long> getExecutionDurationSamples(TaskPriority priority)
Description copied from interface:StatisticPriorityScheduler
Get raw sample data for task run durations. This raw data can be used for more advanced statistics which are not provided in this library. These can also be fed into utilities inStatisticsUtils
for additional statistics.These result set includes all priorities. If you want durations for a specific priority use
StatisticPriorityScheduler.getExecutionDurationSamples(TaskPriority)
.- Specified by:
getExecutionDurationSamples
in interfaceStatisticPriorityScheduler
- Parameters:
priority
- Task priority to provide samples for- Returns:
- A list of task durations in milliseconds
-
getAverageExecutionDuration
public double getAverageExecutionDuration()
Description copied from interface:StatisticPriorityScheduler
Get the average duration that tasks submitted through this executor have spent executing. This only reports samples from tasks which have completed (in-progress tasks are not considered).This call averages over all priority types, if you want the duration for a specific priority use
StatisticPriorityScheduler.getAverageExecutionDuration(TaskPriority)
.- Specified by:
getAverageExecutionDuration
in interfaceStatisticExecutor
- Specified by:
getAverageExecutionDuration
in interfaceStatisticPriorityScheduler
- Returns:
- Average task execution duration in milliseconds
-
getAverageExecutionDuration
public double getAverageExecutionDuration(TaskPriority priority)
Description copied from interface:StatisticPriorityScheduler
Get the average duration that tasks submitted through this executor have spent executing. This only reports samples from tasks which have completed (in-progress tasks are not considered).- Specified by:
getAverageExecutionDuration
in interfaceStatisticPriorityScheduler
- Parameters:
priority
- Specific task priority which statistics should be calculated against- Returns:
- Average task execution duration in milliseconds
-
getExecutionDurationPercentiles
public java.util.Map<java.lang.Double,java.lang.Long> getExecutionDurationPercentiles(double... percentiles)
Description copied from interface:StatisticPriorityScheduler
Gets percentile values for execution duration. This function accepts any decimal percentile between zero and one hundred.The returned map's keys correspond exactly to the percentiles provided. Iterating over the returned map will iterate in order of the requested percentiles as well.
These percentiles are across all priorities combined into the same data set. If you want percentiles for a specific priority use
StatisticPriorityScheduler.getExecutionDurationPercentiles(TaskPriority, double...)
.- Specified by:
getExecutionDurationPercentiles
in interfaceStatisticExecutor
- Specified by:
getExecutionDurationPercentiles
in interfaceStatisticPriorityScheduler
- Parameters:
percentiles
- Percentiles requested, any decimal values between 0 and 100 (inclusive)- Returns:
- Map with keys being the percentiles requested, value being the execution duration in milliseconds
-
getExecutionDurationPercentiles
public java.util.Map<java.lang.Double,java.lang.Long> getExecutionDurationPercentiles(TaskPriority priority, double... percentiles)
Description copied from interface:StatisticPriorityScheduler
Gets percentile values for execution duration. This function accepts any decimal percentile between zero and one hundred.The returned map's keys correspond exactly to the percentiles provided. Iterating over the returned map will iterate in order of the requested percentiles as well.
- Specified by:
getExecutionDurationPercentiles
in interfaceStatisticPriorityScheduler
- Parameters:
priority
- Specific task priority which statistics should be calculated againstpercentiles
- Percentiles requested, any decimal values between 0 and 100 (inclusive)- Returns:
- Map with keys being the percentiles requested, value being the execution duration in milliseconds
-
getLongRunningTasks
public java.util.List<Pair<java.lang.Runnable,java.lang.StackTraceElement[]>> getLongRunningTasks(long durationLimitMillis)
Description copied from interface:StatisticExecutor
Call to get a list of runnables and stack traces from tasks which have been actively executing for a longer duration than the one provided. Time in queue waiting for execution is not considered as part of the execution duration.If only the quantity of long running tasks is needed, please use
StatisticExecutor.getLongRunningTasksQty(long)
. Since it does not need to generate stack traces it is a cheaper alternative.The left side of the
Pair
is the runnable task submitted. If the task was submitted as aCallable
the Runnable will be of type:ListenableFutureTask
. Casting and invokingListenableFutureTask.getContainedCallable()
will allow you to get to your originalCallable
.The right side of the
Pair
is a single sample of what that long running tasks stack was. Because these tasks are running concurrently by the time this function returns the provided tasks may have completed.- Specified by:
getLongRunningTasks
in interfaceStatisticExecutor
- Parameters:
durationLimitMillis
- Limit for tasks execution, if task execution time is below this they will be ignored- Returns:
- List of long running runnables with their corresponding stack traces
-
getLongRunningTasksQty
public int getLongRunningTasksQty(long durationLimitMillis)
Description copied from interface:StatisticExecutor
Call to return the number of tasks which have been running longer than the provided duration in milliseconds. While iterating over running tasks, it may be possible that some previously examine tasks have completed before this ran. There is no attempt to lock tasks from starting or stopping during this check.- Specified by:
getLongRunningTasksQty
in interfaceStatisticExecutor
- Parameters:
durationLimitMillis
- threshold of time in milliseconds a task must have been executing- Returns:
- total quantity of tasks which have or are running longer than the provided time length
-
resetCollectedStats
public void resetCollectedStats()
Description copied from interface:StatisticExecutor
Clears all collected rolling statistics. These are the statistics used for averages and are limited by window sizes.This does NOT reset the total execution counts.
- Specified by:
resetCollectedStats
in interfaceStatisticExecutor
-
getTotalExecutionCount
public long getTotalExecutionCount()
Description copied from interface:StatisticExecutor
Call to get the total quantity of tasks this executor has handled.- Specified by:
getTotalExecutionCount
in interfaceStatisticExecutor
- Returns:
- total quantity of tasks run
-
getTotalExecutionCount
public long getTotalExecutionCount(TaskPriority priority)
Description copied from interface:StatisticPriorityScheduler
Call to get the total quantity of tasks this executor has handled for a specific priority.- Specified by:
getTotalExecutionCount
in interfaceStatisticPriorityScheduler
- Parameters:
priority
- Specific task priority which statistics should be calculated against- Returns:
- total quantity of tasks run
-
-