Class ManagedConnectionMonitor

java.lang.Object
java.lang.Thread
org.tentackle.dbms.ManagedConnectionMonitor
All Implemented Interfaces:
Runnable

@Service(ManagedConnectionMonitor.class) public class ManagedConnectionMonitor extends Thread
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 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().

  • Constructor Details

    • ManagedConnectionMonitor

      public ManagedConnectionMonitor()
      Creates the monitor thread.
  • Method Details

    • getInstance

      public static ManagedConnectionMonitor getInstance()
      Gets the running monitor thread.
      Returns:
      the thread (singleton)
    • isRunning

      public static boolean isRunning()
      Returns whether the monitor is running.
      Useful to avoid getInstance() since this will start it, if not running yet.
      Returns:
      true if running, false if no ManagedConnections created ever (remote server, for example)
    • registerManagedConnection

      public void registerManagedConnection(ManagedConnection managedConnection)
      Registers a managed connection.
      Parameters:
      managedConnection - the managed connection
    • getManagedConnections

      public Collection<ManagedConnection> getManagedConnections()
      Gets a list of all open managed connections.
      Returns:
      the open connections
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • pause

      protected void pause()
      Pauses the thread between loop runs.
    • loop

      protected void loop()
      A single loop run.
    • inspect

      protected void inspect(ManagedConnection managedConnection, long currentTimeMillis)
      Inspects the idle connection.
      Parameters:
      managedConnection - the connection
      currentTimeMillis - the current epochal time