When a new transaction open, it try to use old connection which is expired in connection pool in that case this exception occur. There are multiple way be which your connection can killed by firewall, Third party security server etc. If one thread acquire connection and sleep for more than 8 HR (default connection timeout period for MySQL) then this exception occur if that thread woke up after 8 Hr and try to do transaction with database.
There are two way for solution.
Reduce wait time period in connection pool and reclaim old connection in code. (In connection pool)
Reduce wait time period in Mysql. So that connection from MySQL will reclaim soon.
Steps in order to do above mentioned.
[*]Stop MySQL db server and application server.
[*]Mysql settings: This should be done in "my.ini" file under mysql folder.
wait_timeout =1200 (i.e 20 min – Keep same time of your firewall OR any other third party software)
You can set it DB level by above query. set wait_timeout =1200;
View settings by above query Show variables like 'wait_timeout' ;