Class SingleThreadExecutor
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- org.apache.bookkeeper.common.util.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
SingleThreadExecutor.State
-
Constructor Summary
Constructors Constructor Description SingleThreadExecutor(java.util.concurrent.ThreadFactory tf)
SingleThreadExecutor(java.util.concurrent.ThreadFactory tf, int maxQueueCapacity, boolean rejectExecution)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
void
execute(java.lang.Runnable r)
long
getCompletedTasksCount()
long
getFailedTasksCount()
long
getQueuedTasksCount()
long
getRejectedTasksCount()
long
getSubmittedTasksCount()
boolean
isShutdown()
boolean
isTerminated()
void
registerMetrics(StatsLogger statsLogger)
void
run()
void
shutdown()
java.util.List<java.lang.Runnable>
shutdownNow()
-
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
-
-
-
-
Method Detail
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfacejava.util.concurrent.ExecutorService
-
shutdownNow
public java.util.List<java.lang.Runnable> shutdownNow()
- Specified by:
shutdownNow
in interfacejava.util.concurrent.ExecutorService
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdown
in interfacejava.util.concurrent.ExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminated
in interfacejava.util.concurrent.ExecutorService
-
awaitTermination
public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
awaitTermination
in interfacejava.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 interfacejava.util.concurrent.Executor
-
registerMetrics
public void registerMetrics(StatsLogger statsLogger)
-
-