mysql - DataSource leaves sleeping connections -
i'm using spring , have setup datasource bean:
@bean datasource getdatasource(){ mysqldatasource ds = new mysqldatasource(); ds.seturl(database_url); return ds; }
i'm able inject datasource object using spring's @autowired
annotation , perform operations on database. i'm running against test instance of mysql server (with connection limit of 150) , reached limit within few minutes. checked on number of connections, , majority of 150 connections sleeping.
to decrease number of sleeping connections, i've tried following, none successful:
1) instead of calling datasource.getconnection()
in each of dao's methods, instead @autowired
method called setdatasource(datasource ds)
in saved reference connection. thinking instead of calling datasource.getconnection()
each time, particular instance of dao use 1 connection instead. doing worked fine, , decreased number of sleeping connections, not much.
2) manually called close()
method on connection
object. after doing so, next time made use of datasource (in dao), spring threw error indicating connection closed. (i'm assuming spring does not re-instantiate @beans
?)
3) modified mysql configuration file , set wait_timeout variable few minutes. after sleeping connections cleaned however, received error spring similar seen in #2 (com.mysql.jdbc.exceptions.jdbc4.mysqlnontransientconnectionexception: no operations allowed after connection closed.
, com.mysql.jdbc.exceptions.jdbc4.communicationsexception: communications link failure
)
before attempt rewrite dao operations use jdbctemplate instead of plain-old java sql prepared statements, figured i'd ask here , see if there simple solution.
thanks.
Comments
Post a Comment