I am getting this warning:
WARNING:[PoolCleaner[661646649:1440675349770]] org.apache.tomcat.jdbc.pool.ConnectionPool.abandon Connection has been abandoned PooledConnection[org.postgresql.jdbc4.Jdbc4Connection@7c9e8e2e]: java.lang.Exception For the application, I am using spring framework with Tomcat JDBC pooling and Postgres as database. My configuration file :
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close"> <property name="driverClassName" value="org.postgresql.Driver" /> <property name="url" value="jdbc:postgresql://ip/db" /> <property name="username" value="user" /> <property name="password" value="pass" /> <property name="initialSize" value="5" /> <property name="maxActive" value="10" /> <property name="maxIdle" value="10" /> <property name="testOnBorrow" value="true" /> <property name="validationInterval" value="30000" /> <property name="minIdle" value="5" /> <property name="removeAbandoned" value="true" /> <property name="removeAbandonedTimeout" value="60" /> <property name="logAbandoned" value="true" /> <property name="validationQuery" value="SELECT 1" /> <property name="initSQL" value="SET application_name = 'app'" /> </bean> Here is the problem. From my understanding removeAbandoned should only abandon connections which are in use more than 60 seconds, that is queries that run more than 60 seconds. I do not have such queries at all. But my connections from pool get abandoned.
I suspect that removeAbandoned is removing idle connections in the pool. Though it is not supposed to do so. In my application i am getting connection this way:
//i am using autowiring. @Autowired private DataSource dataSource; //and in my methods i use it this way: Connection conn = dataSource.getConnection(); //and i am closing it after method completion //maybe i should not?? conn.close() UPDATE: I found the error. My Connection variable was global, i made it local to method and everything worked out. Also tested by Apache benchmark, pooling is used. (connections are updated, seen by pg_stat_activity). Thanks for replies.