Class ScheduledObjectOneWorkExecutor<O>

  • Type Parameters:
    O - The type of object for which work is registered.
    All Implemented Interfaces:
    Executor, ExecutorService

    public class ScheduledObjectOneWorkExecutor<O>
    extends AbstractObjectOneWorkExecutor<O,​ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
    This scheduled one work executor handles the usual pending work for before and after a flush. Additionally, it allows to add work with a specific delay. Only one piece of work with delay is allowed for each object. If delayed work exists, additional work will be refused, that is, the waiting work is considered as pending work.
    To realise the delay, the work will be managed by a scheduled executor. After the delay elapsed, the scheduled executor will not execute the delayed work directly but try to add it for normal execution by the object one work executor. For adding delayed work after the delay elapsed the normal restrictions apply, that is, if there is already pending work, the delayed work will be cancelled. If a flush is pending, the delayed work will be pending for after the flush unless such work already exists.

    Adding delayed work will not affect existing pending work. When overriding delayed work, only existing delayed work will be overridden. If there is other pending work as soon as overriding delayed work should be executed, the delayed work will be cancelled.
    When overriding with immediate work, delayed work will be cancelled. When flushing with abortion, delayed work will be ignored.

    • Field Detail

      • scheduled

        protected final ScheduledExecutorService scheduled
        The scheduled executor service executing runnables which add work that should be delayed.
      • delays

        protected final ThreadLocal<Queue<Long>> delays
        The delays for scheduled and submitted work. This is required since the interface of the superclass does not know the delays and does not have them in the API.
        To allow for nested/reentrant submissions and schedules, each call to a schedule or submit method adds a delay to this queue. Submissions without delay use -1.
    • Constructor Detail

      • ScheduledObjectOneWorkExecutor

        @Deprecated(since="14.4.0",
                    forRemoval=true)
        public ScheduledObjectOneWorkExecutor​(boolean blockUntilFlush,
                                              Adept2ThreadFactory threadFactory)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Creates a new thread pool executor with an unlimited amount of threads and objects, accepting exactly one piece of work per object. It uses the designated thread factory for creating threads. The threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with two threads also using the designated thread factory.
        Parameters:
        blockUntilFlush - Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.
        threadFactory - The factory to use when the (scheduled) executor creates a new thread.
      • ScheduledObjectOneWorkExecutor

        public ScheduledObjectOneWorkExecutor​(boolean blockUntilFlush,
                                              int maxPoolSize,
                                              Adept2ThreadFactory threadFactory)
        Creates a new thread pool executor with an unlimited amount of objects and the designated maximum amount of threads, accepting exactly one piece of work per object. It uses the designated thread factory for creating threads. The threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with two threads also using the designated thread factory.
        Parameters:
        blockUntilFlush - Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.
        maxPoolSize - The maximum number of threads allowed in the pool. Set this to the number of objects allowed to be executed concurrently or less.
        threadFactory - The factory to use when the (scheduled) executor creates a new thread.
      • ScheduledObjectOneWorkExecutor

        public ScheduledObjectOneWorkExecutor​(boolean blockUntilFlush,
                                              int corePoolSize,
                                              int maxPoolSize,
                                              int scheduledPoolSize,
                                              Adept2ThreadFactory threadFactory)
        Creates a new thread pool executor with the designated (maximum) amount of (core) threads (and unlimited objects), accepting exactly one piece of work per object. It uses the designated thread factory for creating threads. The threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with the designated amount of threads and also using the designated thread factory.
        Parameters:
        blockUntilFlush - Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.
        corePoolSize - The number of threads to keep in the pool of the executor service all the time, even if they are idle.
        maxPoolSize - The maximum number of threads allowed in the pool. Set this to the number of objects allowed to be executed concurrently or less.
        scheduledPoolSize - The number of threads to keep in the pool of the separate scheduled executor service, even if they are idle. These threads are not for executing work but for enqueuing delayed work.
        threadFactory - The factory to use when the (scheduled) executor creates a new thread.
      • ScheduledObjectOneWorkExecutor

        @Deprecated(since="14.4.0",
                    forRemoval=true)
        public ScheduledObjectOneWorkExecutor​(boolean blockUntilFlush,
                                              int corePoolSize,
                                              int maxPoolSize,
                                              boolean prestart,
                                              int scheduledPoolSize,
                                              Adept2ThreadFactory threadFactory)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Creates a new thread pool executor with the designated (maximum) amount of (core) threads (and unlimited objects), accepting exactly one piece of work per object. It uses the designated thread factory for creating threads. The threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with the designated amount of threads and also using the designated thread factory.
        Parameters:
        blockUntilFlush - Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.
        corePoolSize - The number of threads to keep in the pool of the executor service, even if they are idle.
        maxPoolSize - The maximum number of threads to allow in the pool of the executor service.
        prestart - Whether all core threads in the executor service should be prestarted.
        scheduledPoolSize - The number of threads to keep in the pool of the separate scheduled executor service, even if they are idle. These threads are not for executing work but for enqueuing delayed work.
        threadFactory - The factory to use when the (scheduled) executor creates a new thread.
      • ScheduledObjectOneWorkExecutor

        public ScheduledObjectOneWorkExecutor​(boolean blockUntilFlush,
                                              int corePoolSize,
                                              int maxPoolSize,
                                              int scheduledPoolSize,
                                              Comparator<? super Runnable> comparator,
                                              Adept2ThreadFactory threadFactory,
                                              int queueLimitPoolStatistics,
                                              Level minLogLevelPoolStatistics)
        Creates a new thread pool executor with the designated (maximum) amount of (core) threads, accepting exactly one piece of work per object. The work will be prioritised using the designated comparator, work exceeding the threads will be enqueued. The executor uses the designated thread factory for creating threads. The non-core threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with the designated amount of threads and also using the same thread factory.
        Parameters:
        blockUntilFlush - Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.
        corePoolSize - The number of threads to keep in the (object work) pool all the time, even if they are idle.
        maxPoolSize - The maximum number of threads allowed in the (object work) pool. Set this to the number of objects allowed to be executed concurrently or less.
        scheduledPoolSize - The number of threads to keep in the pool of the separate scheduled executor service, even if they are idle. These threads are not for executing work but for enqueuing delayed work.
        comparator - The comparator used to determine the priority of work.
        threadFactory - The factory to use when the executor creates a new thread. Also the logger from this thread factory will be used by this executor.
        queueLimitPoolStatistics - The amount of tasks in the queue before warnings will be logged. Use -1 to use the default limits.
        minLogLevelPoolStatistics - The log level which need to be reached for logging pool statistics. Pool statistics logs with a lower log level will be ignored.
      • ScheduledObjectOneWorkExecutor

        @Deprecated(since="14.4.0",
                    forRemoval=true)
        public ScheduledObjectOneWorkExecutor​(boolean blockUntilFlush,
                                              int corePoolSize,
                                              int maxPoolSize,
                                              boolean prestart,
                                              int scheduledPoolSize,
                                              Comparator<? super Runnable> comparator,
                                              Adept2ThreadFactory threadFactory,
                                              int queueLimitPoolStatistics,
                                              Level minLogLevelPoolStatistics)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Creates a new thread pool executor with the designated (maximum) amount of (core) threads, accepting exactly one piece of work per object. The work will be prioritised using the designated comparator, work exceeding the threads will be enqueued. The executor uses the designated thread factory for creating threads. The non-core threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with the designated amount of threads and also using the same thread factory.
        Parameters:
        blockUntilFlush - Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.
        corePoolSize - The number of threads to keep in the (object work) pool, even if they are idle.
        maxPoolSize - The maximum number of threads to allow in the (object work) pool.
        prestart - Whether all core threads should be prestarted.
        scheduledPoolSize - The number of threads to keep in the pool of the separate scheduled executor service, even if they are idle. These threads are not for executing work but for enqueuing delayed work.
        comparator - The comparator used to determine the priority of work.
        threadFactory - The factory to use when the executor creates a new thread. Also the logger from this thread factory will be used by this executor.
        queueLimitPoolStatistics - The amount of tasks in the queue before warnings will be logged. Use -1 to use the default limits.
        minLogLevelPoolStatistics - The log level which need to be reached for logging pool statistics. Pool statistics logs with a lower log level will be ignored.
      • ScheduledObjectOneWorkExecutor

        public ScheduledObjectOneWorkExecutor​(boolean blockUntilFlush,
                                              int corePoolSize,
                                              int maxPoolSize,
                                              int scheduledPoolSize,
                                              Comparator<? super Runnable> comparator,
                                              Adept2ThreadFactory threadFactory,
                                              Level minLogLevelPoolStatistics)
        Creates a new thread pool executor with the designated (maximum) amount of (core) threads, accepting exactly one piece of work per object. The work will be prioritised using the designated comparator, work exceeding the threads will be enqueued. The executor uses the designated thread factory for creating threads. The non-core threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with the designated amount of threads and also using the same thread factory.
        Parameters:
        blockUntilFlush - Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.
        corePoolSize - The number of threads to keep in the (object work) pool all the time, even if they are idle.
        maxPoolSize - The maximum number of threads allowed in the (object work) pool. Set this to the number of objects allowed to be executed concurrently or less.
        scheduledPoolSize - The number of threads to keep in the pool of the separate scheduled executor service, even if they are idle. These threads are not for executing work but for enqueuing delayed work.
        comparator - The comparator used to determine the priority of work.
        threadFactory - The factory to use when the executor creates a new thread. Also the logger from this thread factory will be used by this executor.
        minLogLevelPoolStatistics - The log level which need to be reached for logging pool statistics. Pool statistics logs with a lower log level will be ignored.
      • ScheduledObjectOneWorkExecutor

        @Deprecated(since="14.4.0",
                    forRemoval=true)
        public ScheduledObjectOneWorkExecutor​(boolean blockUntilFlush,
                                              int corePoolSize,
                                              int maxPoolSize,
                                              boolean prestart,
                                              int scheduledPoolSize,
                                              Comparator<? super Runnable> comparator,
                                              Adept2ThreadFactory threadFactory,
                                              Level minLogLevelPoolStatistics)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Creates a new thread pool executor with the designated (maximum) amount of (core) threads, accepting exactly one piece of work per object. The work will be prioritised using the designated comparator, work exceeding the threads will be enqueued. The executor uses the designated thread factory for creating threads. The non-core threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with the designated amount of threads and also using the same thread factory.
        Parameters:
        blockUntilFlush - Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.
        corePoolSize - The number of threads to keep in the (object work) pool, even if they are idle.
        maxPoolSize - The maximum number of threads to allow in the (object work) pool.
        prestart - Whether all core threads should be prestarted.
        scheduledPoolSize - The number of threads to keep in the pool of the separate scheduled executor service, even if they are idle. These threads are not for executing work but for enqueuing delayed work.
        comparator - The comparator used to determine the priority of work.
        threadFactory - The factory to use when the executor creates a new thread. Also the logger from this thread factory will be used by this executor.
        minLogLevelPoolStatistics - The log level which need to be reached for logging pool statistics. Pool statistics logs with a lower log level will be ignored.