java - HikariCP Connection leak -


i'm working on game runs on java server. database pooling i'm using hikaricp, excellent library, throwing following error way:

[hikari housekeeper (pool hikaripool-0)] warn com.zaxxer.hikari.pool.proxyleaktask - connection leak detection triggered connection com.mysql.jdbc.jdbc4connection@5910e440, stack trace follows java.lang.exception: apparent connection leak detected     @ nl.finicky.lemonade.database.database.prepare(database.java:43)     @ nl.finicky.lemonade.rooms.roomfactory.loadroom(roomfactory.java:25)     @ nl.finicky.lemonade.rooms.roomfactory.<init>(roomfactory.java:20)     @ nl.finicky.lemonade.lemonade.main(lemonade.java:30) 

now know connection leak means open connection floating around somewhere, can't figure out how or where.

the following method in database class, error should occur according stack trace.

public preparedstatement prepare(string query) {     preparedstatement statement = null;      try {         while (statement == null) {             statement = this.datasource.getconnection().preparestatement(query, 1);  // line triggering error ^              if (statement != null) {                 this.databasepool.getstorage();             }         }     } catch (sqlexception e) {         e.printstacktrace();     } {         return statement;     } } 

this basic method initiate statement. when called, use , call resultset.close(), preparedstatement.getconnection.close() , preparedstatement.close()

still tells me connection open.

how solve this? thanks!

calling preparedstatement.getconnection.close() later merely different connection , close it.

you can't trying kind of pattern. calling this.datasource.getconnection().preparestatement(...) getting connection pool , throwing away reference it, after nobody can close it. , can't close connection in method, if retained reference it, because returned preparedstatement unusable.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -