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, tick
execute, getDefaultPriority, getMaxWaitForLowPriority, getQueuedTaskCount, getQueuedTaskCount, getWaitingForExecutionTaskCount, getWaitingForExecutionTaskCount, remove, remove, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, setMaxWaitForLowPriority, submit, submit, submitScheduled, submitScheduled
schedule, submitScheduled, submitScheduled
execute, submit, submit
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getQueuedTaskCount
execute, getDefaultPriority, getMaxWaitForLowPriority, getQueuedTaskCount, getWaitingForExecutionTaskCount, schedule, submit, submit, submit, submitScheduled, submitScheduled, submitScheduled
getActiveTaskCount, getQueuedTaskCount, getWaitingForExecutionTaskCount, isShutdown, remove, remove
schedule, scheduleAtFixedRate, scheduleWithFixedDelay, submitScheduled, submitScheduled, submitScheduled
submit, submit, submit
public 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)
PrioritySchedulerService
recurringDelay + 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 PrioritySchedulerService
scheduleWithFixedDelay
in class NoThreadScheduler
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 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 PrioritySchedulerService
scheduleAtFixedRate
in class NoThreadScheduler
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 onpublic java.util.List<java.lang.Long> getExecutionDelaySamples()
StatisticPriorityScheduler
StatisticsUtils
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 StatisticExecutor
getExecutionDelaySamples
in interface StatisticPriorityScheduler
public java.util.List<java.lang.Long> getExecutionDelaySamples(TaskPriority priority)
StatisticPriorityScheduler
StatisticPriorityScheduler.getAverageExecutionDelay(TaskPriority)
. This call
allows for more complex statistics (ie looking for outliers, etc).getExecutionDelaySamples
in interface StatisticPriorityScheduler
priority
- 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 StatisticExecutor
getAverageExecutionDelay
in interface StatisticPriorityScheduler
public double getAverageExecutionDelay(TaskPriority priority)
StatisticPriorityScheduler
getAverageExecutionDelay
in interface StatisticPriorityScheduler
priority
- Specific task priority which statistics should be calculated againstpublic java.util.Map<java.lang.Double,java.lang.Long> getExecutionDelayPercentiles(double... percentiles)
StatisticPriorityScheduler
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...)
.
getExecutionDelayPercentiles
in interface StatisticExecutor
getExecutionDelayPercentiles
in interface StatisticPriorityScheduler
percentiles
- 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)
StatisticPriorityScheduler
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.
getExecutionDelayPercentiles
in interface StatisticPriorityScheduler
priority
- 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()
StatisticPriorityScheduler
StatisticsUtils
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 StatisticExecutor
getExecutionDurationSamples
in interface StatisticPriorityScheduler
public java.util.List<java.lang.Long> getExecutionDurationSamples(TaskPriority priority)
StatisticPriorityScheduler
StatisticsUtils
for additional statistics.
These result set includes all priorities. If you want durations for a specific priority use
StatisticPriorityScheduler.getExecutionDurationSamples(TaskPriority)
.
getExecutionDurationSamples
in interface StatisticPriorityScheduler
priority
- 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 StatisticExecutor
getAverageExecutionDuration
in interface StatisticPriorityScheduler
public double getAverageExecutionDuration(TaskPriority priority)
StatisticPriorityScheduler
getAverageExecutionDuration
in interface StatisticPriorityScheduler
priority
- Specific task priority which statistics should be calculated againstpublic java.util.Map<java.lang.Double,java.lang.Long> getExecutionDurationPercentiles(double... percentiles)
StatisticPriorityScheduler
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...)
.
getExecutionDurationPercentiles
in interface StatisticExecutor
getExecutionDurationPercentiles
in interface StatisticPriorityScheduler
percentiles
- 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)
StatisticPriorityScheduler
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.
getExecutionDurationPercentiles
in interface StatisticPriorityScheduler
priority
- 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 StatisticExecutor
durationLimitMillis
- Limit for tasks execution, if task execution time is below this they will be ignoredpublic int getLongRunningTasksQty(long durationLimitMillis)
StatisticExecutor
getLongRunningTasksQty
in interface StatisticExecutor
durationLimitMillis
- threshold of time in milliseconds a task must have been executingpublic void resetCollectedStats()
StatisticExecutor
This does NOT reset the total execution counts.
resetCollectedStats
in interface StatisticExecutor
public long getTotalExecutionCount()
StatisticExecutor
getTotalExecutionCount
in interface StatisticExecutor
public long getTotalExecutionCount(TaskPriority priority)
StatisticPriorityScheduler
getTotalExecutionCount
in interface StatisticPriorityScheduler
priority
- Specific task priority which statistics should be calculated against