java.lang.Object
java.lang.Thread
net.i2p.util.I2PThread
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
CountryLookup.LookupThread, Elg2KeyFactory, I2PAppThread, JobQueueRunner, MLKEMKeyFactory, PeerManager.ReorgThread, X25519KeyFactory
Preferred over
Thread for all router uses. For applications, I2PAppThread is preferred.Provides the following features:
- Logging to wrapper log on unexpected termination in
run(). - Notification of OOM to registered listener (the router), which will cause logging to the wrapper log and a router restart
- Catching and logging "OOM" caused by thread limit in
start()with distinct message, and does not call the OOM listener. - As of 0.9.21, initialization to NORM_PRIORITY (not the priority of the creating thread).
Nested Class Summary
Nested ClassesModifier 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 static final Set<I2PThread.OOMEventListener> OOM listeners registered for every threadFields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITYConstructor Summary
ConstructorsConstructorDescriptionI2PThread.I2PThread.I2PThread.I2PThread.I2PThread.I2PThread(ThreadGroup g, Runnable r) I2PThread.I2PThread(ThreadGroup group, Runnable r, String name) Create a named thread in the given group, at normal priority.Method Summary
Modifier 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.voidrun()Run the thread, catching and reporting OOM and other failures.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
_listeners
OOM listeners registered for every thread
Constructor Details
I2PThread
public I2PThread()I2PThread.I2PThread
I2PThread.- Parameters:
name- the thread name shown in logs and thread dumps
I2PThread
I2PThread
I2PThread
I2PThread
I2PThread.- Parameters:
g- the thread group the new thread joins, which decides its default priorityr- the body the new thread runs
I2PThread
Create a named thread in the given group, at normal priority.- Parameters:
group- the thread group the new thread joinsr- the body the new thread runsname- the thread name shown in logs and thread dumps
Method Details
start
public void start()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. If the calling thread is an I2PThread an OOM would shut down the JVM. Telling the user to increase the heap size may make the problem worse. We may be able to continue without this thread, particularly in app context.run
fireOOM
Notify listeners that an OutOfMemoryError occurred.- Parameters:
oom- the error passed to every registered listener
addOOMEventListener
Register a new component that wants notification of OOM events.- Parameters:
lsnr- the listener to add, ignored if already registered
removeOOMEventListener
Unregister a component that wants notification of OOM events.- Parameters:
lsnr- the listener to drop, a no-op if it is not registered