Class SingleThreadExecutor

  • All Implemented Interfaces:
    java.lang.Runnable, java.util.concurrent.Executor, java.util.concurrent.ExecutorService

    public class SingleThreadExecutor
    extends java.util.concurrent.AbstractExecutorService
    implements java.util.concurrent.ExecutorService, java.lang.Runnable
    Implements a single thread executor that drains the queue in batches to minimize contention between threads.

    Tasks are executed in a safe manner: if there are exceptions they are logged and the executor will proceed with the next tasks.

    • Constructor Detail

      • SingleThreadExecutor

        public SingleThreadExecutor​(java.util.concurrent.ThreadFactory tf)
      • SingleThreadExecutor

        public SingleThreadExecutor​(java.util.concurrent.ThreadFactory tf,
                                    int maxQueueCapacity,
                                    boolean rejectExecution)
    • Method Detail

      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • shutdown

        public void shutdown()
        Specified by:
        shutdown in interface java.util.concurrent.ExecutorService
      • shutdownNow

        public java.util.List<java.lang.Runnable> shutdownNow()
        Specified by:
        shutdownNow in interface java.util.concurrent.ExecutorService
      • isShutdown

        public boolean isShutdown()
        Specified by:
        isShutdown in interface java.util.concurrent.ExecutorService
      • isTerminated

        public boolean isTerminated()
        Specified by:
        isTerminated in interface java.util.concurrent.ExecutorService
      • awaitTermination

        public boolean awaitTermination​(long timeout,
                                        java.util.concurrent.TimeUnit unit)
                                 throws java.lang.InterruptedException
        Specified by:
        awaitTermination in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
      • getQueuedTasksCount

        public long getQueuedTasksCount()
      • getSubmittedTasksCount

        public long getSubmittedTasksCount()
      • getCompletedTasksCount

        public long getCompletedTasksCount()
      • getRejectedTasksCount

        public long getRejectedTasksCount()
      • getFailedTasksCount

        public long getFailedTasksCount()
      • execute

        public void execute​(java.lang.Runnable r)
        Specified by:
        execute in interface java.util.concurrent.Executor
      • registerMetrics

        public void registerMetrics​(StatsLogger statsLogger)