0

I am using root as username.

My program will refresh every 5 seconds. What it does is, it query from mysql table and display the data.

Problem is, every after 5 seconds, the connection on mysql will append, reason that it will give an error of "TOO MUCH CONNECTIONS" when it reach the limit.

Is it possible to kill the previous connection since it is unused already?

Here is my code on opening a connection.

connectionPool = connectionPool.getConnectionPool("root", "*****", "");
AyukNayr
  • 386
  • 2
  • 21
  • Close all connections ? http://jpos.org/doc/javadoc/org/jpos/tpl/ConnectionPool.html – Sudipta Mondal Jun 21 '18 at 10:06
  • 1
    Use connection pooling and increase max_connection variable according to your MySQL server capacity – Sumesh TG Jun 21 '18 at 10:07
  • @SudiptaMondal Not all connections. previous connections only. Since ths program will continue to run – AyukNayr Jun 21 '18 at 10:17
  • 1
    @SumeshTG what about when it hits the new limit? You are just ignoring the real problem. – tanaydin Jun 21 '18 at 11:03
  • Should set timeout for every connections @tanaydin – Sumesh TG Jun 21 '18 at 11:09
  • @SumeshTG which one is correct :) max_connection or timeout? you are suggesting a different thing to defense first suggestion... timeout for connection is for "connection" not for "idle connections", it gets fired if the connection is not established given time. – tanaydin Jun 21 '18 at 13:11
  • @tanaydin I solved this situation by profiling mysql server(set max_con,increase cache .. etc) and kill all idle connection by executing query in another thread using processing id dynamically. Some connection become idle after timeout. – Sumesh TG Jun 21 '18 at 13:35
  • @SumeshTG this is not a solution, this is cover. It is ridiculous to close "idle" connections with another one. What should you do if this "disconnector" can't connect because of connection limit? You have to free pool instance or close connection after your execution is over, then you don't need another thread for "disconnecting" previous connections. – tanaydin Jun 22 '18 at 11:49

2 Answers2

0

This is normal behavior if you are using a connection pool. When your job is over be sure that you free the connection instance, or close all pool connections when your code execution is done.

tanaydin
  • 5,171
  • 28
  • 45
  • So there is no way to close the previous connection? since it will refresh every 5s, it will open another connection while the previous connection is not usable anymore. – AyukNayr Jun 21 '18 at 10:01
  • you have to close your own connection, you shouldn't leave it for next execution. – tanaydin Jun 21 '18 at 11:02
  • add a finally and close the used connection @AyukNayr – Sumesh TG Jun 21 '18 at 11:11
0

When you are done with a connection, you need to close it. this will return a connection back to the pool.

ipolevoy
  • 5,432
  • 2
  • 31
  • 46