java.lang.Object
java.lang.Thread
net.i2p.util.I2PThread
net.i2p.router.JobQueueRunner
- All Implemented Interfaces:
Runnable
Worker thread that executes jobs from the router job queue. Handles job execution, timing collection, error handling, and performance monitoring for individual job processing threads.
Nested Class Summary
Nested classes/interfaces inherited from class I2PThread
I2PThread.OOMEventListenerModifier and TypeClassDescriptionstatic interfaceListener for out-of-memory events.Nested classes/interfaces inherited from class Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandlerField Summary
FieldsModifier and TypeFieldDescriptionprivate final RouterContextThe router context.private JobThe job running right now.private final intThe id of this runner.private RateStatCached "jobQueue.jobLag" handle, resolved on first use.private RateStatCached "jobQueue.jobRun" handle, resolved on first use.private RateStatCached "jobQueue.jobWait" handle, resolved on first use.private booleanTrue while the runner should keep running.private longWhen the last job began.private longWhen the last job ended.private JobThe job that ran last.private final LogThe log for the runner.Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITYConstructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionThe job currently being executed.longWhen the job that ran most recently started.longWhen the job that ran most recently finished, stats update included.The most recently completed job.intIdentifier for this runner.private voidResolve the cached RateStat handles for the three per-job stats.voidrun()Run the thread, catching and reporting OOM and other failures.private voidRuns the job taken from the queue.voidStart the runner.voidStop the runner.Methods inherited from class I2PThread
addOOMEventListener, fireOOM, removeOOMEventListener, startModifier and TypeMethodDescriptionstatic voidRegister a new component that wants notification of OOM events.protected voidfireOOM(OutOfMemoryError oom) Notify listeners that an OutOfMemoryError occurred.static voidUnregister a component that wants notification of OOM events.voidstart()Overridden to provide useful info to users on OOM, and to prevent shutting down the whole JVM for what is most likely not a heap issue.Methods inherited from class Thread
activeCount, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, startVirtualThread, threadId, toString, yield
Field Details
_log
The log for the runner._context
The router context._keepRunning
private volatile boolean _keepRunningTrue while the runner should keep running._id
private final int _idThe id of this runner._currentJob
The job running right now._lastJob
The job that ran last._lastBegin
private volatile long _lastBeginWhen the last job began._lastEnd
private volatile long _lastEndWhen the last job ended._jobRunStat
Cached "jobQueue.jobRun" handle, resolved on first use. Null until resolved, and it stays null whenstat.fullis off (in which case JobQueue's createRateStat() is a no-op). Resolution is idempotent, so a benign race can only assign the same handle twice._jobLagStat
Cached "jobQueue.jobLag" handle, resolved on first use. @since 0.9.71+._jobWaitStat
Cached "jobQueue.jobWait" handle, resolved on first use. @since 0.9.71+.
Constructor Details
JobQueueRunner
Create a new job queue runner.- Parameters:
context- the router contextid- the runner id
Method Details
getCurrentJob
getLastJob
getRunnerId
public int getRunnerId()Identifier for this runner.- Returns:
- the runner id
stopRunning
public void stopRunning()Stop the runner.startRunning
public void startRunning()Start the runner.getLastBegin
public long getLastBegin()When the job that ran most recently started.- Returns:
- adjusted time in ms, 0 until the first job has started
getLastEnd
public long getLastEnd()When the job that ran most recently finished, stats update included.- Returns:
- adjusted time in ms, 0 until the first job has finished
resolveStats
private void resolveStats()Resolve the cached RateStat handles for the three per-job stats.Every job used to pay three string-keyed ConcurrentHashMap lookups in StatManager, and each handle then fans out to a synchronized Rate per period - nine monitor acquisitions per job across three periods. The stats are created once by the JobQueue constructor before any runner exists, so caching the handles removes the lookups without changing which rates receive data. Left null when the stat was never created (
stat.fulloff), in which case the update is skipped, matchingStatManager.addRateData(String, long, long)'s own no-op.run
runCurrentJob
private void runCurrentJob()Runs the job taken from the queue.