public class NoThreadSchedulerStatisticTracker extends NoThreadScheduler implements StatisticPriorityScheduler
NoThreadScheduler which tracks run and usage statistics. This is
designed for testing and troubleshooting. It has a little more overhead from the normal
NoThreadScheduler.
It helps give insight in how long tasks are running, how well the thread pool is being
utilized, as well as execution frequency.| Constructor and Description |
|---|
NoThreadSchedulerStatisticTracker()
Constructs a new
NoThreadSchedulerStatisticTracker scheduler. |
NoThreadSchedulerStatisticTracker(int maxStatisticWindowSize)
Constructs a new
NoThreadSchedulerStatisticTracker scheduler. |
NoThreadSchedulerStatisticTracker(int maxStatisticWindowSize,
boolean accurateTime)
Constructs a new
NoThreadSchedulerStatisticTracker scheduler. |
NoThreadSchedulerStatisticTracker(TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs)
Constructs a new
NoThreadSchedulerStatisticTracker scheduler with specified default
priority behavior. |
NoThreadSchedulerStatisticTracker(TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
int maxStatisticWindowSize)
Constructs a new
NoThreadSchedulerStatisticTracker scheduler. |
NoThreadSchedulerStatisticTracker(TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
int maxStatisticWindowSize,
boolean accurateTime)
Constructs a new
NoThreadSchedulerStatisticTracker scheduler, specifying all available
construction options. |
| Modifier and Type | Method and 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.
|
blockingTick, cancelTick, clearTasks, getActiveTaskCount, getDelayTillNextTask, hasTaskReadyToRun, isShutdown, tickexecute, getDefaultPriority, getMaxWaitForLowPriority, getQueuedTaskCount, getQueuedTaskCount, getWaitingForExecutionTaskCount, getWaitingForExecutionTaskCount, remove, remove, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, setMaxWaitForLowPriority, submit, submit, submitScheduled, submitScheduledschedule, submitScheduled, submitScheduledexecute, submit, submitequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetQueuedTaskCountexecute, getDefaultPriority, getMaxWaitForLowPriority, getQueuedTaskCount, getWaitingForExecutionTaskCount, schedule, submit, submit, submit, submitScheduled, submitScheduled, submitScheduledgetActiveTaskCount, getQueuedTaskCount, getWaitingForExecutionTaskCount, isShutdown, remove, removeschedule, scheduleAtFixedRate, scheduleWithFixedDelay, submitScheduled, submitScheduled, submitScheduledsubmit, submit, submitpublic NoThreadSchedulerStatisticTracker()
NoThreadSchedulerStatisticTracker scheduler.
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.
public NoThreadSchedulerStatisticTracker(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs)
NoThreadSchedulerStatisticTracker scheduler with specified default
priority behavior.
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.
defaultPriority - Default priority for tasks which are submitted without any specified prioritymaxWaitForLowPriorityInMs - time low priority tasks to wait if there are high priority tasks ready to runpublic NoThreadSchedulerStatisticTracker(int maxStatisticWindowSize)
NoThreadSchedulerStatisticTracker scheduler.
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.
maxStatisticWindowSize - maximum number of samples to keep internallypublic NoThreadSchedulerStatisticTracker(int maxStatisticWindowSize,
boolean accurateTime)
NoThreadSchedulerStatisticTracker scheduler.maxStatisticWindowSize - maximum number of samples to keep internallyaccurateTime - true to ensure that delays and durations are not under reportedpublic NoThreadSchedulerStatisticTracker(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, int maxStatisticWindowSize)
NoThreadSchedulerStatisticTracker scheduler.defaultPriority - Default priority for tasks which are submitted without any specified prioritymaxWaitForLowPriorityInMs - time low priority tasks to wait if there are high priority tasks ready to runmaxStatisticWindowSize - maximum number of samples to keep internallypublic NoThreadSchedulerStatisticTracker(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, int maxStatisticWindowSize, boolean accurateTime)
NoThreadSchedulerStatisticTracker scheduler, specifying all available
construction options.defaultPriority - Default priority for tasks which are submitted without any specified prioritymaxWaitForLowPriorityInMs - time low priority tasks to wait if there are high priority tasks ready to runmaxStatisticWindowSize - maximum number of samples to keep internallyaccurateTime - true to ensure that delays and durations are not under reportedpublic void scheduleWithFixedDelay(java.lang.Runnable task,
long initialDelay,
long recurringDelay,
TaskPriority priority)
PrioritySchedulerServicerecurringDelay + 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).
scheduleWithFixedDelay in interface PrioritySchedulerServicescheduleWithFixedDelay in class NoThreadSchedulertask - 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 onpublic void scheduleAtFixedRate(java.lang.Runnable task,
long initialDelay,
long period,
TaskPriority priority)
PrioritySchedulerService
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).
scheduleAtFixedRate in interface PrioritySchedulerServicescheduleAtFixedRate in class NoThreadSchedulertask - 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 onpublic java.util.List<java.lang.Long> getExecutionDelaySamples()
StatisticPrioritySchedulerStatisticsUtils for additional statistics.
The returned result set includes all priorities. If you want durations for a specific
priority use StatisticPriorityScheduler.getExecutionDelaySamples(TaskPriority).
getExecutionDelaySamples in interface StatisticExecutorgetExecutionDelaySamples in interface StatisticPrioritySchedulerpublic java.util.List<java.lang.Long> getExecutionDelaySamples(TaskPriority priority)
StatisticPrioritySchedulerStatisticPriorityScheduler.getAverageExecutionDelay(TaskPriority). This call
allows for more complex statistics (ie looking for outliers, etc).getExecutionDelaySamples in interface StatisticPrioritySchedulerpriority - Task priority to provide samples forpublic double getAverageExecutionDelay()
StatisticPriorityScheduler-1 if no samples have been
collected yet. This call averages over all priority types, if you want the delay for a
specific priority use StatisticPriorityScheduler.getAverageExecutionDelay(TaskPriority).getAverageExecutionDelay in interface StatisticExecutorgetAverageExecutionDelay in interface StatisticPrioritySchedulerpublic double getAverageExecutionDelay(TaskPriority priority)
StatisticPrioritySchedulergetAverageExecutionDelay in interface StatisticPrioritySchedulerpriority - Specific task priority which statistics should be calculated againstpublic java.util.Map<java.lang.Double,java.lang.Long> getExecutionDelayPercentiles(double... percentiles)
StatisticPrioritySchedulerThe 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...).
getExecutionDelayPercentiles in interface StatisticExecutorgetExecutionDelayPercentiles in interface StatisticPrioritySchedulerpercentiles - Percentiles requested, any decimal values between 0 and 100 (inclusive)public java.util.Map<java.lang.Double,java.lang.Long> getExecutionDelayPercentiles(TaskPriority priority, double... percentiles)
StatisticPrioritySchedulerThe 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.
getExecutionDelayPercentiles in interface StatisticPrioritySchedulerpriority - Specific task priority which statistics should be calculated againstpercentiles - Percentiles requested, any decimal values between 0 and 100 (inclusive)public java.util.List<java.lang.Long> getExecutionDurationSamples()
StatisticPrioritySchedulerStatisticsUtils for additional statistics.
The returned result set includes all priorities. If you want durations for a specific
priority use StatisticPriorityScheduler.getExecutionDurationSamples(TaskPriority).
getExecutionDurationSamples in interface StatisticExecutorgetExecutionDurationSamples in interface StatisticPrioritySchedulerpublic java.util.List<java.lang.Long> getExecutionDurationSamples(TaskPriority priority)
StatisticPrioritySchedulerStatisticsUtils for additional statistics.
These result set includes all priorities. If you want durations for a specific priority use
StatisticPriorityScheduler.getExecutionDurationSamples(TaskPriority).
getExecutionDurationSamples in interface StatisticPrioritySchedulerpriority - Task priority to provide samples forpublic double getAverageExecutionDuration()
StatisticPriorityScheduler
This call averages over all priority types, if you want the duration for a specific priority
use StatisticPriorityScheduler.getAverageExecutionDuration(TaskPriority).
getAverageExecutionDuration in interface StatisticExecutorgetAverageExecutionDuration in interface StatisticPrioritySchedulerpublic double getAverageExecutionDuration(TaskPriority priority)
StatisticPrioritySchedulergetAverageExecutionDuration in interface StatisticPrioritySchedulerpriority - Specific task priority which statistics should be calculated againstpublic java.util.Map<java.lang.Double,java.lang.Long> getExecutionDurationPercentiles(double... percentiles)
StatisticPrioritySchedulerThe 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...).
getExecutionDurationPercentiles in interface StatisticExecutorgetExecutionDurationPercentiles in interface StatisticPrioritySchedulerpercentiles - Percentiles requested, any decimal values between 0 and 100 (inclusive)public java.util.Map<java.lang.Double,java.lang.Long> getExecutionDurationPercentiles(TaskPriority priority, double... percentiles)
StatisticPrioritySchedulerThe 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.
getExecutionDurationPercentiles in interface StatisticPrioritySchedulerpriority - Specific task priority which statistics should be calculated againstpercentiles - Percentiles requested, any decimal values between 0 and 100 (inclusive)public java.util.List<Pair<java.lang.Runnable,java.lang.StackTraceElement[]>> getLongRunningTasks(long durationLimitMillis)
StatisticExecutor
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 a Callable the Runnable will be of type:
ListenableFutureTask. Casting and invoking
ListenableFutureTask.getContainedCallable() will allow
you to get to your original Callable.
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.
getLongRunningTasks in interface StatisticExecutordurationLimitMillis - Limit for tasks execution, if task execution time is below this they will be ignoredpublic int getLongRunningTasksQty(long durationLimitMillis)
StatisticExecutorgetLongRunningTasksQty in interface StatisticExecutordurationLimitMillis - threshold of time in milliseconds a task must have been executingpublic void resetCollectedStats()
StatisticExecutorThis does NOT reset the total execution counts.
resetCollectedStats in interface StatisticExecutorpublic long getTotalExecutionCount()
StatisticExecutorgetTotalExecutionCount in interface StatisticExecutorpublic long getTotalExecutionCount(TaskPriority priority)
StatisticPrioritySchedulergetTotalExecutionCount in interface StatisticPrioritySchedulerpriority - Specific task priority which statistics should be calculated against