Search code examples
javajpaeclipselink

Eclipselink: how to check if connection pool is used


I use eclipselink 2.6.3 and I need to know exactly if connection pool is created and used by Eclipselink or not.

I have the following settings if persistence.xml

<property name="eclipselink.connection-pool.default.initial" value="5" />
<property name="eclipselink.connection-pool.default.min" value="10" />
<property name="eclipselink.connection-pool.default.max" value="10" />
<property name="eclipselink.jdbc.cache-statements" value="true" />

However, the logs are the same for both cases - when I use these settings and when I don't:

[EL Finer]: connection: 2017-01-22 19:39:03.208--ServerSession(1440738283)--client acquired: 1177072083
[EL Finer]: transaction: 2017-01-22 19:39:03.218--ClientSession(1177072083)--acquire unit of work: 1482166692
[EL Finest]: query: 2017-01-22 19:39:03.239--UnitOfWork(1482166692)--Execute query ReadObjectQuery(...)
[EL Finest]: connection: 2017-01-22 19:39:03.243--ServerSession(1440738283)--Connection(2008547236)--Connection acquired from connection pool [read].
[EL Finest]: connection: 2017-01-22 19:39:03.243--ServerSession(1440738283)--reconnecting to external connection pool
[EL Fine]: sql: 2017-01-22 19:39:03.244--ServerSession(1440738283)--Connection(1590792382)-- SELECT ...
[EL Finest]: connection: 2017-01-22 19:39:03.25--ServerSession(1440738283)--Connection(2008547236)--Connection released to connection pool [read].
[EL Finer]: transaction: 2017-01-22 19:39:03.257--UnitOfWork(1482166692)--release unit of work
[EL Finer]: connection: 2017-01-22 19:39:03.257--ClientSession(1177072083)--client released

Could anyone say how to check using of connection pool.


Solution

  • EclipseLink can operate in two modes. When you provide a JDBC URL and pool properties, as you have done, EclipseLInk will create and manage the Connection Pool. The implementation for the pool is org.eclipse.persistence.sessions.server.ConnectionPool. The alternative is to provide a DataSource, either through a JNDI reference, or programatically. The second option is often used in Application servers, where the server will manage the connection pool, and EclipseLink will ask the DataSource whenever it needs a new connection.

    If you want to check if the connections are pooled, you will most likely have to do it from the database side. All databases allow you to see a list of connections and their id, and which query they are currently executing. This should allow you to see if connections are pooled, or if new connections are constantly created. You could also set a breakpoint in org.eclipse.persistence.sessions.server.ConnectionPool#acquireConnection() and step through the code.