public class SingleThreadSchedulerStatisticTracker extends SingleThreadScheduler implements StatisticPriorityScheduler
SingleThreadScheduler
which tracks run and usage statistics. This
is designed for testing and troubleshooting. It has a little more overhead from the normal
SingleThreadScheduler
.
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 |
---|
SingleThreadSchedulerStatisticTracker()
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(boolean daemonThread)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(boolean daemonThread,
int maxStatisticWindowSize)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(boolean daemonThread,
int maxStatisticWindowSize,
boolean accurateTime)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(int maxStatisticWindowSize)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(int maxStatisticWindowSize,
boolean accurateTime)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
boolean daemonThread)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
boolean daemonThread,
int maxStatisticWindowSize)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
boolean daemonThread,
int maxStatisticWindowSize,
boolean accurateTime)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
int maxStatisticWindowSize)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
int maxStatisticWindowSize,
boolean accurateTime)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
java.util.concurrent.ThreadFactory threadFactory)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
java.util.concurrent.ThreadFactory threadFactory,
int maxStatisticWindowSize)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
java.util.concurrent.ThreadFactory threadFactory,
int maxStatisticWindowSize,
boolean accurateTime)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(java.util.concurrent.ThreadFactory threadFactory)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(java.util.concurrent.ThreadFactory threadFactory,
int maxStatisticWindowSize)
Constructs a new
SingleThreadScheduler . |
SingleThreadSchedulerStatisticTracker(java.util.concurrent.ThreadFactory threadFactory,
int maxStatisticWindowSize,
boolean accurateTime)
Constructs a new
SingleThreadScheduler . |
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.
|
java.util.List<java.lang.Runnable> |
shutdownNow()
Stops any new tasks from being submitted to the pool.
|
awaitTermination, awaitTermination, getActiveTaskCount, isShutdown, isTerminated, prestartExecutionThread, prestartExecutionThread, scheduleAtFixedRate, scheduleWithFixedDelay, shutdown
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, scheduleAtFixedRate, scheduleWithFixedDelay, submit, submit, submit, submitScheduled, submitScheduled, submitScheduled
getActiveTaskCount, getQueuedTaskCount, getWaitingForExecutionTaskCount, isShutdown, remove, remove
schedule, scheduleAtFixedRate, scheduleWithFixedDelay, submitScheduled, submitScheduled, submitScheduled
submit, submit, submit
public SingleThreadSchedulerStatisticTracker()
SingleThreadScheduler
. No threads will start until the first task
is provided. This defaults to using a daemon thread for the 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 SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs)
SingleThreadScheduler
. No threads will start until the first task
is provided. This defaults to using a daemon thread for the 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.
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 SingleThreadSchedulerStatisticTracker(boolean daemonThread)
SingleThreadScheduler
. No threads will start until the first task
is provided.
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.
daemonThread
- true
if scheduler thread should be a daemon threadpublic SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, boolean daemonThread)
SingleThreadScheduler
. No threads will start until the first task
is provided.
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 rundaemonThread
- true
if scheduler thread should be a daemon threadpublic SingleThreadSchedulerStatisticTracker(java.util.concurrent.ThreadFactory threadFactory)
SingleThreadScheduler
. No threads will start until the first task
is provided.
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.
threadFactory
- factory to make thread for schedulerpublic SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, java.util.concurrent.ThreadFactory threadFactory)
SingleThreadScheduler
. No threads will start until the first task
is provided.
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 runthreadFactory
- factory to make thread for schedulerpublic SingleThreadSchedulerStatisticTracker(int maxStatisticWindowSize)
SingleThreadScheduler
. No threads will start until the first task
is provided. This defaults to using a daemon thread for the 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 SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, int maxStatisticWindowSize)
SingleThreadScheduler
. No threads will start until the first task
is provided. This defaults to using a daemon thread for the 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.
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 SingleThreadSchedulerStatisticTracker(boolean daemonThread, int maxStatisticWindowSize)
SingleThreadScheduler
. No threads will start until the first task
is provided.
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.
daemonThread
- true
if scheduler thread should be a daemon threadmaxStatisticWindowSize
- maximum number of samples to keep internallypublic SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, boolean daemonThread, int maxStatisticWindowSize)
SingleThreadScheduler
. No threads will start until the first task
is provided.
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 rundaemonThread
- true
if scheduler thread should be a daemon threadmaxStatisticWindowSize
- maximum number of samples to keep internallypublic SingleThreadSchedulerStatisticTracker(java.util.concurrent.ThreadFactory threadFactory, int maxStatisticWindowSize)
SingleThreadScheduler
. No threads will start until the first task
is provided.
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.
threadFactory
- factory to make thread for schedulermaxStatisticWindowSize
- maximum number of samples to keep internallypublic SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, java.util.concurrent.ThreadFactory threadFactory, int maxStatisticWindowSize)
SingleThreadScheduler
. No threads will start until the first task
is provided.
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 runthreadFactory
- factory to make thread for schedulermaxStatisticWindowSize
- maximum number of samples to keep internallypublic SingleThreadSchedulerStatisticTracker(int maxStatisticWindowSize, boolean accurateTime)
SingleThreadScheduler
. No threads will start until the first task
is provided. This defaults to using a daemon thread for the scheduler.maxStatisticWindowSize
- maximum number of samples to keep internallyaccurateTime
- true
to ensure that delays and durations are not under reportedpublic SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, int maxStatisticWindowSize, boolean accurateTime)
SingleThreadScheduler
. No threads will start until the first task
is provided. This defaults to using a daemon thread for the 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 internallyaccurateTime
- true
to ensure that delays and durations are not under reportedpublic SingleThreadSchedulerStatisticTracker(boolean daemonThread, int maxStatisticWindowSize, boolean accurateTime)
SingleThreadScheduler
. No threads will start until the first task
is provided.daemonThread
- true
if scheduler thread should be a daemon threadmaxStatisticWindowSize
- maximum number of samples to keep internallyaccurateTime
- true
to ensure that delays and durations are not under reportedpublic SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, boolean daemonThread, int maxStatisticWindowSize, boolean accurateTime)
SingleThreadScheduler
. No threads will start until the first task
is provided.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 rundaemonThread
- true
if scheduler thread should be a daemon threadmaxStatisticWindowSize
- maximum number of samples to keep internallyaccurateTime
- true
to ensure that delays and durations are not under reportedpublic SingleThreadSchedulerStatisticTracker(java.util.concurrent.ThreadFactory threadFactory, int maxStatisticWindowSize, boolean accurateTime)
SingleThreadScheduler
. No threads will start until the first task
is provided.threadFactory
- factory to make thread for schedulermaxStatisticWindowSize
- maximum number of samples to keep internallyaccurateTime
- true
to ensure that delays and durations are not under reportedpublic SingleThreadSchedulerStatisticTracker(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, java.util.concurrent.ThreadFactory threadFactory, int maxStatisticWindowSize, boolean accurateTime)
SingleThreadScheduler
. No threads will start until the first task
is provided.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 runthreadFactory
- factory to make thread for schedulermaxStatisticWindowSize
- maximum number of samples to keep internallyaccurateTime
- true
to ensure that delays and durations are not under reportedpublic java.util.List<java.lang.Runnable> shutdownNow()
SingleThreadScheduler
shutdownNow
in class SingleThreadScheduler
public 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