Skip to content

Martini Managing JDBC Connections

In Martini, database connections are efficiently managed through a connection pool to facilitate reuse across requests. However, it's essential to understand how to handle potential issues like reaching connection limits or encountering leaks.

Connection Pool Management

Each database pool in Martini maintains a maximum number of open connections based on its properties. When this limit is reached or exceeded, it can lead to connection unavailability during runtime.

Detecting Connection Leaks

While Martini attempts to return connections to their pools after use, you may encounter connection leaks under certain circumstances. To monitor JDBC connections for potential leaks, you can enable stacktrace recording upon connection creation.

Monitoring JDBC Connections

To enable stacktrace recording:

  1. From the Martini Designer menu bar, select Martini > Open Logs.
  2. On the right side, click on Configure Loggers.
  3. Set the logger level of io.toro.martini.database to DEBUG.
  4. Use the getDatabaseConnections operation from the REST API to query connection metadata.

If io.toro.martini.database is not present in the list of logger names, you can manually add it by pressing the + button on the right.

Sample Response

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
  "totalResults": 5,
  "totalPages": 1,
  "page": 0,
  "limit": 5,
  "items": [
    {
      "name": "coder-722795987",
      "createdAt": "2024-04-02 11:00:04",
      "stackTrace": [
        "GetCustomers.InvokeGloop(GetCustomers.gloop:17)",
        "io.toro.martini.database.BitronixConnectionRegistry.onAcquire(BitronixConnectionRegistry.java:67)",
        "bitronix.tm.resource.jdbc.PoolingDataSource.fireOnAcquire(PoolingDataSource.java:225)",
        "bitronix.tm.resource.jdbc.JdbcPooledConnection.<init>(JdbcPooledConnection.java:118)",
        "bitronix.tm.resource.jdbc.PoolingDataSource.createPooledConnection(PoolingDataSource.java:341)",
        "bitronix.tm.resource.common.XAPool.createPooledObject(XAPool.java:283)",
        "bitronix.tm.resource.common.XAPool.grow(XAPool.java:391)",
        "bitronix.tm.resource.common.XAPool.getInPool(XAPool.java:371)",
      ]
    }
  ]
}

This response indicates the existence of an active connection named coder-722795987 from the coder database pool. It was initiated and opened by the GetEmployees Gloop service at line 17.

Important Considerations

  • Recorded connections are only available after configuring the log level to DEBUG.
  • Previous connections are not returned by the API.
  • For immediate tracking, restart the database pool to reset connections.
  • Remember to revert the log level after troubleshooting to avoid performance overhead.