I have to correct an existing Java Backend application implemented in Java 8 with no Framework, and deployed on Tomcat server under Linux Virtual Machine. This application is connected to an Oracle Database and access it via JDBC, with no ORM, no JPA, only with JDBC.
I have a very strange error that occurs, where it indicates a message very different than the context where this exception occurs.
For some cases (hopefully not all cases, a minority of cases),
when in the code i try to get a connection from the JDBC pool
connection = datasource.getConnection()
In the logs I obtain this error:
Pooled object created 2025-02-06 22:04:02 +0100 by the following code has not been returned to the pool:
org.apache.tomcat.dbcp.pool2.impl.ThrowableCallStack$Snapshot
at org.apache.tomcat.dbcp.pool2.impl.ThrowableCallStack.fillInStackTrace(ThrowableCallStack.java:71)
at org.apache.tomcat.dbcp.pool2.impl.DefaultPooledObject.allocate(DefaultPooledObject.java:193)
at org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:439)
at org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:345)
at org.apache.tomcat.dbcp.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:794)
at company.ws.utils.DBUtility.getMosaicConnection(DBUtility.java:43)
And at the line 43 of the getMosaicConnection
of the class DBUtility
,
I have this instruction:
connection = datasource.getConnection();
What it can cause such problem?
Can it be a problem of code? All the connections taken from the pool are closed in a finally block, all the connections.
Could it be a problem of Tomcat configuration in server.xml
file?
Have you encounter already such a problem and what have you done to fix it?
Thanks a lot.