Class SingleThreadSchedulerStatisticTracker

    • Constructor Detail

      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker()
        Constructs a new 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.

      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(TaskPriority defaultPriority,
                                                     long maxWaitForLowPriorityInMs)
        Constructs a new 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.

        Parameters:
        defaultPriority - Default priority for tasks which are submitted without any specified priority
        maxWaitForLowPriorityInMs - time low priority tasks to wait if there are high priority tasks ready to run
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(boolean daemonThread)
        Constructs a new 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.

        Parameters:
        daemonThread - true if scheduler thread should be a daemon thread
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(TaskPriority defaultPriority,
                                                     long maxWaitForLowPriorityInMs,
                                                     boolean daemonThread)
        Constructs a new 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.

        Parameters:
        defaultPriority - Default priority for tasks which are submitted without any specified priority
        maxWaitForLowPriorityInMs - time low priority tasks to wait if there are high priority tasks ready to run
        daemonThread - true if scheduler thread should be a daemon thread
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(java.util.concurrent.ThreadFactory threadFactory)
        Constructs a new 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.

        Parameters:
        threadFactory - factory to make thread for scheduler
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(TaskPriority defaultPriority,
                                                     long maxWaitForLowPriorityInMs,
                                                     java.util.concurrent.ThreadFactory threadFactory)
        Constructs a new 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.

        Parameters:
        defaultPriority - Default priority for tasks which are submitted without any specified priority
        maxWaitForLowPriorityInMs - time low priority tasks to wait if there are high priority tasks ready to run
        threadFactory - factory to make thread for scheduler
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(int maxStatisticWindowSize)
        Constructs a new 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.

        Parameters:
        maxStatisticWindowSize - maximum number of samples to keep internally
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(TaskPriority defaultPriority,
                                                     long maxWaitForLowPriorityInMs,
                                                     int maxStatisticWindowSize)
        Constructs a new 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.

        Parameters:
        defaultPriority - Default priority for tasks which are submitted without any specified priority
        maxWaitForLowPriorityInMs - time low priority tasks to wait if there are high priority tasks ready to run
        maxStatisticWindowSize - maximum number of samples to keep internally
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(boolean daemonThread,
                                                     int maxStatisticWindowSize)
        Constructs a new 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.

        Parameters:
        daemonThread - true if scheduler thread should be a daemon thread
        maxStatisticWindowSize - maximum number of samples to keep internally
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(TaskPriority defaultPriority,
                                                     long maxWaitForLowPriorityInMs,
                                                     boolean daemonThread,
                                                     int maxStatisticWindowSize)
        Constructs a new 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.

        Parameters:
        defaultPriority - Default priority for tasks which are submitted without any specified priority
        maxWaitForLowPriorityInMs - time low priority tasks to wait if there are high priority tasks ready to run
        daemonThread - true if scheduler thread should be a daemon thread
        maxStatisticWindowSize - maximum number of samples to keep internally
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(java.util.concurrent.ThreadFactory threadFactory,
                                                     int maxStatisticWindowSize)
        Constructs a new 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.

        Parameters:
        threadFactory - factory to make thread for scheduler
        maxStatisticWindowSize - maximum number of samples to keep internally
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(TaskPriority defaultPriority,
                                                     long maxWaitForLowPriorityInMs,
                                                     java.util.concurrent.ThreadFactory threadFactory,
                                                     int maxStatisticWindowSize)
        Constructs a new 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.

        Parameters:
        defaultPriority - Default priority for tasks which are submitted without any specified priority
        maxWaitForLowPriorityInMs - time low priority tasks to wait if there are high priority tasks ready to run
        threadFactory - factory to make thread for scheduler
        maxStatisticWindowSize - maximum number of samples to keep internally
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(int maxStatisticWindowSize,
                                                     boolean accurateTime)
        Constructs a new SingleThreadScheduler. No threads will start until the first task is provided. This defaults to using a daemon thread for the scheduler.
        Parameters:
        maxStatisticWindowSize - maximum number of samples to keep internally
        accurateTime - true to ensure that delays and durations are not under reported
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(TaskPriority defaultPriority,
                                                     long maxWaitForLowPriorityInMs,
                                                     int maxStatisticWindowSize,
                                                     boolean accurateTime)
        Constructs a new SingleThreadScheduler. No threads will start until the first task is provided. This defaults to using a daemon thread for the scheduler.
        Parameters:
        defaultPriority - Default priority for tasks which are submitted without any specified priority
        maxWaitForLowPriorityInMs - time low priority tasks to wait if there are high priority tasks ready to run
        maxStatisticWindowSize - maximum number of samples to keep internally
        accurateTime - true to ensure that delays and durations are not under reported
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(boolean daemonThread,
                                                     int maxStatisticWindowSize,
                                                     boolean accurateTime)
        Constructs a new SingleThreadScheduler. No threads will start until the first task is provided.
        Parameters:
        daemonThread - true if scheduler thread should be a daemon thread
        maxStatisticWindowSize - maximum number of samples to keep internally
        accurateTime - true to ensure that delays and durations are not under reported
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(TaskPriority defaultPriority,
                                                     long maxWaitForLowPriorityInMs,
                                                     boolean daemonThread,
                                                     int maxStatisticWindowSize,
                                                     boolean accurateTime)
        Constructs a new SingleThreadScheduler. No threads will start until the first task is provided.
        Parameters:
        defaultPriority - Default priority for tasks which are submitted without any specified priority
        maxWaitForLowPriorityInMs - time low priority tasks to wait if there are high priority tasks ready to run
        daemonThread - true if scheduler thread should be a daemon thread
        maxStatisticWindowSize - maximum number of samples to keep internally
        accurateTime - true to ensure that delays and durations are not under reported
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(java.util.concurrent.ThreadFactory threadFactory,
                                                     int maxStatisticWindowSize,
                                                     boolean accurateTime)
        Constructs a new SingleThreadScheduler. No threads will start until the first task is provided.
        Parameters:
        threadFactory - factory to make thread for scheduler
        maxStatisticWindowSize - maximum number of samples to keep internally
        accurateTime - true to ensure that delays and durations are not under reported
      • SingleThreadSchedulerStatisticTracker

        public SingleThreadSchedulerStatisticTracker​(TaskPriority defaultPriority,
                                                     long maxWaitForLowPriorityInMs,
                                                     java.util.concurrent.ThreadFactory threadFactory,
                                                     int maxStatisticWindowSize,
                                                     boolean accurateTime)
        Constructs a new SingleThreadScheduler. No threads will start until the first task is provided.
        Parameters:
        defaultPriority - Default priority for tasks which are submitted without any specified priority
        maxWaitForLowPriorityInMs - time low priority tasks to wait if there are high priority tasks ready to run
        threadFactory - factory to make thread for scheduler
        maxStatisticWindowSize - maximum number of samples to keep internally
        accurateTime - 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: SingleThreadScheduler
        Stops any new tasks from being submitted to the pool. If any tasks are waiting for execution they will be prevented from being run. If a task is currently running it will be allowed to finish (though this call will not block waiting for it to finish).
        Overrides:
        shutdownNow in class SingleThreadScheduler
        Returns:
        returns a list of runnables which were waiting in the queue to be run at time of shutdown
      • 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 interface StatisticPriorityScheduler
        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 interface StatisticExecutor
        Specified by:
        getExecutionDelayPercentiles in interface StatisticPriorityScheduler
        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 interface StatisticPriorityScheduler
        Parameters:
        priority - Specific task priority which statistics should be calculated against
        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
      • 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 interface StatisticPriorityScheduler
        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 interface StatisticExecutor
        Specified by:
        getExecutionDurationPercentiles in interface StatisticPriorityScheduler
        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 interface StatisticPriorityScheduler
        Parameters:
        priority - Specific task priority which statistics should be calculated against
        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
      • 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 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.

        Specified by:
        getLongRunningTasks in interface StatisticExecutor
        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 interface StatisticExecutor
        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 interface StatisticExecutor
      • 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 interface StatisticExecutor
        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 interface StatisticPriorityScheduler
        Parameters:
        priority - Specific task priority which statistics should be calculated against
        Returns:
        total quantity of tasks run