I have a TimerTask that runs once (about 1 or 2 hours) every day. And every time it starts, it will create hundreds of threads to do some computational work for each table in the MySQL database. and I use c3p0 as the connection pool of the database source (each thread receives a connection before computing and closes the connection after computing). I set up the connection pool configuration as shown below
cpDs = new ComboPooledDataSource();
cpDs.setMinPoolSize(10);
cpDs.setMaxPoolSize(20);
cpDs.setMaxStatementsPerConnection(10);
During testing, I found that all database connections were lost the next day, and there were a lot of “communication failures” in the log file due to a major exception. ”So I added the following configurations to check the connection before using it.
// 7 hours, less than MYSQL default value - 8 hours
cpDs.setMaxIdleTime(25200);
cpDs.setTestConnectionOnCheckout(true);
cpDs.setPreferredTestQuery("select 1");
but I notice that there are always 10 connections that remain idle / idle (via SQL 'show processlist;') when the TimerTask is down and I often see the famous "APPARENT DEADLOCK !!!" warning (that the error is still in the open state in the c3p0 project http://sourceforge.net/tracker/?func=detail&aid=3432139&group_id=25357&atid=383690 ).
, , , ? .
,