I am currently working on Dropwizard framework project with EclipseLink JPA. I need to get connection pool statistics such as the number of active connections, the total number of connections, etc. I tried with the below method, but it always shows the same data. Please help me in solving this problem.
EntityManager entityManager = (EntityManager) unitOfWorkI.getContext();
ServerSession serverSession = entityManager.unwrap(ServerSession.class);
for (Map.Entry<String, ConnectionPool> entry: serverSession.getConnectionPools().entrySet()) {
System.out.println("Connection Pool Name: " + entry.getKey());
System.out.println("Min number of Connections: " + entry.getValue().getMinNumberOfConnections());
System.out.println("Max number of Connections: " + entry.getValue().getMaxNumberOfConnections());
System.out.println("Connections in use: " + (entry.getValue().getMaxNumberOfConnections() - entry.getValue().getConnectionsAvailable().size()));
}
entityManager.close();