Sunday, March 21, 2010

never keep java.sql.connection for later use

from c++ and framework development background, i also try to minimize repeated tasks in program cycle. my recent discovery is to get java.sql.connection at application initialization and keep it for application runtime use. so far so good, no problem during development time, since server never up for more than 10 hours. but once it put it for deployment, i received this error

mysql connection disconnected: The last packet successfully received from the server was 312,686,980 milliseconds ago

I first i thought is my server OS shutdown the harddisk or network system after long period of idling. after much debugging, i found that is my own wonderful code causes this problem. to solve it i should getConnection everytime connection is required.

No comments: