A recent observation of the production environment found a phenomenon, a period of time do not operate, and then re-operation, the first time the database connection will appear: Java.sql.SQLException:Already closed., as follows:
The data source was managed with the Tomcat DBCP based on the Jndi configuration, which was looked up as follows:
Reason:
You ' re probably running to the fact that MYSQL closes connections which has been open "too long".
Probably If you do the request to the server again, and you'll find that it works because the connection is reopened.
Workaround:
One-to-deal with the-is-to- add the following to your context.xml Resource:
validationquery= "SELECT 1" (based on MySQL)
validationquery= "Select 1 from Dual" (Oracle-based)
Price:
This causes a very cheap test query to always be run first; if the connection have been closed, this gets the failure, and
Then a new connection is opened.
Think of the original configuration with WebLogic jdbc Jndi There is a special configuration item to configure this test query, and it is careless to configure Tomcat: (