public class ActionQueueThread extends Thread
This a simple queue that runs as a thread and executes passed
in action object (i.e. Runnable
instances) in a
sequence. It can be configured with a maximum size. When this maximum
size is reached and a new element is added to it, it will not return
until some percentage of the accumulated actions has been completed.
Thread.State, Thread.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_FREE_PERCENT_ON_BLOCK |
static int |
DEFAULT_NON_BLOCKING_SIZE |
static int |
PAUSE_GRANULARITY_ACTIONS
Thread can be paused every n actions.
|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
ActionQueueThread()
Default constructor.
|
ActionQueueThread(String name)
Constructs an
ActionQueue with a specific thread
name and a default max size. |
ActionQueueThread(String name,
int maxSizeBeforeBlock,
int completePercentUponBlocking)
Constructs an
ActionQueue with a specific thread
name and max size. |
Modifier and Type | Method and Description |
---|---|
void |
addAction(Runnable action) |
void |
clearAll()
Clear all actions.
|
void |
completeAll()
Complete all scheduled actions at the time of this call.
|
long |
getCompletedCount()
Return the total number of actions executed by this thread, whether or not
the actions have terminated with an exception.
|
boolean |
isRunning() |
void |
pauseActions()
Suspend the execution of actions until the
resumeActions method is
called. |
void |
prependAction(Runnable action)
Put an action in front of the queue so that it's executed
next or close to next.
|
void |
resumeActions()
Resume action processing previously paused by a call to
pauseActions . |
void |
run() |
void |
stopRunning() |
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public static final int DEFAULT_NON_BLOCKING_SIZE
public static final int DEFAULT_FREE_PERCENT_ON_BLOCK
public static final int PAUSE_GRANULARITY_ACTIONS
public ActionQueueThread()
Default constructor. Unnamed action queue with a default max size.
public ActionQueueThread(String name)
Constructs an ActionQueue
with a specific thread
name and a default max size.
name
- The name of the action queue thread.public ActionQueueThread(String name, int maxSizeBeforeBlock, int completePercentUponBlocking)
Constructs an ActionQueue
with a specific thread
name and max size.
name
- The name of the action queue thread.maxSizeBeforeBlock
- The maximum number of actions waiting in the queue
before this ActionQueue
blocks a calling thread.completPercentUponBlocking
- The amount, in percent, of action to execute
from a filled up queue before we return to the blocked thread.public void pauseActions()
Suspend the execution of actions until the resumeActions
method is
called. Blocks until all current actions (@see PAUSE_GRANULARITY_ACTIONS)
complete execution.
public void resumeActions()
Resume action processing previously paused by a call to pauseActions
.
public void addAction(Runnable action)
public void prependAction(Runnable action)
Put an action in front of the queue so that it's executed next or close to next. This method will not block even if the size of the accumulated actions exceeds the blocking threshold
public void completeAll()
Complete all scheduled actions at the time of this call. Since other threads may keep adding actions, this method makes sure that only the actions in the queue at the time of the call are waited upon.
public void clearAll()
Clear all actions. The currently executing actions will still complete, but all others will be removed.
public long getCompletedCount()
Return the total number of actions executed by this thread, whether or not the actions have terminated with an exception.
public boolean isRunning()
public void stopRunning()
Copyright © 2015. All rights reserved.