java.lang.Object
java.lang.Thread
org.tentackle.dbms.ManagedConnectionMonitor
- All Implemented Interfaces:
Runnable
Maintains a set of all open managed connections.
The connections are held by a weak reference and the set is cleaned up once a minute.
Optionally, idle connections with
The connections are held by a weak reference and the set is cleaned up once a minute.
Optionally, idle connections with
ManagedConnection.isConnectionVerificationNecessary()
== true
will be verified (via dummy selects) periodically and to prevent premature closing by the database backend.
This is especially useful for databases running in the cloud, where the idle connection interval
cannot be deactivated or made longer than the idle times maintained by the MpxConnectionManager
.
Notice: the monitor thread never stops! It is started when first referenced by
getInstance()
.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ManagedConnectionMonitor
Gets the running monitor thread.Gets a list of all open managed connections.protected void
inspect
(ManagedConnection managedConnection, long currentTimeMillis) Inspects the idle connection.static boolean
Returns whether the monitor is running.
Useful to avoidgetInstance()
since this will start it, if not running yet.protected void
loop()
A single loop run.protected void
pause()
Pauses the thread between loop runs.void
registerManagedConnection
(ManagedConnection managedConnection) Registers a managed connection.void
run()
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, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Constructor Details
-
ManagedConnectionMonitor
public ManagedConnectionMonitor()Creates the monitor thread.
-
-
Method Details
-
getInstance
Gets the running monitor thread.- Returns:
- the thread (singleton)
-
isRunning
public static boolean isRunning()Returns whether the monitor is running.
Useful to avoidgetInstance()
since this will start it, if not running yet.- Returns:
- true if running, false if no
ManagedConnection
s created ever (remote server, for example)
-
registerManagedConnection
Registers a managed connection.- Parameters:
managedConnection
- the managed connection
-
getManagedConnections
Gets a list of all open managed connections.- Returns:
- the open connections
-
run
public void run() -
pause
protected void pause()Pauses the thread between loop runs. -
loop
protected void loop()A single loop run. -
inspect
Inspects the idle connection.- Parameters:
managedConnection
- the connectioncurrentTimeMillis
- the current epochal time
-