Class EClient.RQThread
- java.lang.Object
-
- java.lang.Thread
-
- net.sf.eBus.client.EClient.RQThread
-
- All Implemented Interfaces:
java.lang.Runnable
- Enclosing class:
- EClient
public static final class EClient.RQThread extends java.lang.Thread
A Dispatcher run queue thread watches a givenrun queue
forEClient
instances ready to run, attempting to acquire the next ready client. When the thread successfully acquires a client, this thread has the client execute its pending tasks until either 1) the client has no more tasks or 2) the client exhausts its run quantum. Each run queue has a configurable run quantum (default isEConfigure.DEFAULT_QUANTUM
). When a client exhausts this quantum and still has tasks to run, the client is placed at the end of the run queue and its quantum is replenished.A client instance is referenced by only one dispatcher thread at time. This means a client is effectively single-threaded at any given instance while it may be accessed by multiple, different dispatcher threads over time.
Note: this only applies to eBus threads. Non-eBus threads may still access the client object at the same time.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EClient.RQThread.RQThreadState
A run queue thread is either idle (waiting for an available eBus object) or busy (running an eBus object).
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
NO_EOBJECT
Set eBus object name to "(idle)" when run queue thread is idle.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
alarmCondition(AlarmCondition alarmState)
Sets maximum quantum overrun alarm condition.RQThreadInfo
currentInfo()
Returns this run queue thread's current information.EClient.RQStats
currentStats()
Returns this run queue thread's current stats.long
maximumQuantum()
Returns configured maximum quantum for this run queue thread.void
run()
A client executor thread continues processing ready eBus clients until the JVM exits.EClient
spinSleepPoll()
Spins a fixed number of times callingConcurrentLinkedQueue.poll()
to extract the next available client from the run queue.EClient
spinYieldPoll()
Spins a fixed number of times callingConcurrentLinkedQueue.poll()
to extract the next available client from the run queue.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
NO_EOBJECT
public static final java.lang.String NO_EOBJECT
Set eBus object name to "(idle)" when run queue thread is idle.- See Also:
- Constant Field Values
-
-
Method Detail
-
run
public void run()
A client executor thread continues processing ready eBus clients until the JVM exits. On each iteration, this thread acquires the next available client. Then iterates over the client's task list and executing each task. This continues until the client has no more tasks or has used up its runtime quantum. The client is put back on the run queue (if the quantum is expired, the value is reset to the configured maximum) and this thread goes back to the loop's top and acquires the next available client.Because an eBus client is posted to only one, unique run queue and each
Dispatcher
thread works with only one run queue, once a dispatcher thread acquires an eBus client, it is guaranteed that no other dispatcher thread has access to the client. Therefore, from an eBus perspective, eBus client access is single-threaded.(Non-eBus threads may still access a client simultaneously as a dispatcher thread. This is an application design decision.)
- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
currentStats
public EClient.RQStats currentStats()
Returns this run queue thread's current stats. May returnnull
.- Returns:
- current run queue stats.
-
currentInfo
public RQThreadInfo currentInfo()
Returns this run queue thread's current information.- Returns:
- run queue thread information.
-
maximumQuantum
public long maximumQuantum()
Returns configured maximum quantum for this run queue thread.- Returns:
- run queue thread maximum quantum.
-
alarmCondition
public void alarmCondition(AlarmCondition alarmState)
Sets maximum quantum overrun alarm condition.- Parameters:
alarmState
- thread overrun alarm condition.
-
spinSleepPoll
public EClient spinSleepPoll()
Spins a fixed number of times callingConcurrentLinkedQueue.poll()
to extract the next available client from the run queue. When the spin limit is reached, then parks for a fixed number of nanoseconds.- Returns:
- next available client. Does not return
null
.
-
spinYieldPoll
public EClient spinYieldPoll()
Spins a fixed number of times callingConcurrentLinkedQueue.poll()
to extract the next available client from the run queue. When the spin limit is reached, then this Dispatcher thread yields.- Returns:
- next available client. Does not return
null
.
-
-