public class PrioritySchedulerStatisticTracker extends PriorityScheduler implements StatisticPriorityScheduler
PriorityScheduler which tracks run and usage statistics. This is
designed for testing and troubleshooting. It has a little more overhead from the normal
PriorityScheduler.
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 |
|---|
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)
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)
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)
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,
int maxStatisticWindowSize)
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)
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.
|
| 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.
|
java.util.List<java.lang.Runnable> |
shutdownNow()
Stops any new tasks from being able to be executed and removes workers from the pool.
|
adjustPoolSize, awaitTermination, awaitTermination, getActiveTaskCount, getCurrentPoolSize, getMaxPoolSize, getQueuedTaskCount, getQueuedTaskCount, isShutdown, prestartAllThreads, setPoolSize, shutdownexecute, getDefaultPriority, getMaxWaitForLowPriority, 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 PrioritySchedulerStatisticTracker(int poolSize)
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.
poolSize - Thread pool size that should be maintainedpublic PrioritySchedulerStatisticTracker(int poolSize,
boolean useDaemonThreads)
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.
poolSize - Thread pool size that should be maintaineduseDaemonThreads - true if newly created threads should be daemonpublic PrioritySchedulerStatisticTracker(int poolSize,
TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs)
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.
poolSize - Thread pool size that should be maintaineddefaultPriority - priority to give tasks which do not specify itmaxWaitForLowPriorityInMs - time low priority tasks wait for a workerpublic PrioritySchedulerStatisticTracker(int poolSize,
TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
boolean useDaemonThreads)
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.
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 daemonpublic PrioritySchedulerStatisticTracker(int poolSize,
TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
java.util.concurrent.ThreadFactory threadFactory)
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.
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 executorpublic PrioritySchedulerStatisticTracker(int poolSize,
int maxStatisticWindowSize)
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.
poolSize - Thread pool size that should be maintainedmaxStatisticWindowSize - maximum number of samples to keep internallypublic PrioritySchedulerStatisticTracker(int poolSize,
boolean useDaemonThreads,
int maxStatisticWindowSize)
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.
poolSize - Thread pool size that should be maintaineduseDaemonThreads - true if newly created threads should be daemonmaxStatisticWindowSize - maximum number of samples to keep internallypublic PrioritySchedulerStatisticTracker(int poolSize,
TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
int maxStatisticWindowSize)
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.
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 internallypublic PrioritySchedulerStatisticTracker(int poolSize,
TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
boolean useDaemonThreads,
int maxStatisticWindowSize)
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.
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 internallypublic PrioritySchedulerStatisticTracker(int poolSize,
TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
java.util.concurrent.ThreadFactory threadFactory,
int maxStatisticWindowSize)
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.
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 internallypublic PrioritySchedulerStatisticTracker(int poolSize,
int maxStatisticWindowSize,
boolean accurateTime)
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 reportedpublic PrioritySchedulerStatisticTracker(int poolSize,
boolean useDaemonThreads,
int maxStatisticWindowSize,
boolean accurateTime)
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 reportedpublic PrioritySchedulerStatisticTracker(int poolSize,
TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
int maxStatisticWindowSize,
boolean accurateTime)
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 reportedpublic PrioritySchedulerStatisticTracker(int poolSize,
TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
boolean useDaemonThreads,
int maxStatisticWindowSize,
boolean accurateTime)
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 reportedpublic PrioritySchedulerStatisticTracker(int poolSize,
TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
java.util.concurrent.ThreadFactory threadFactory,
int maxStatisticWindowSize,
boolean accurateTime)
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 reportedpublic java.util.List<java.lang.Runnable> shutdownNow()
PrioritySchedulerThis 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.
shutdownNow in class PrioritySchedulerpublic 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 PrioritySchedulertask - 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 PrioritySchedulertask - 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