
Mysql服務器預設的「wait_timeout」是8小時(待查證),所以mysql配置中my.ini 的wait_timeout值一定要大於等於connection pool的idle_timeout 值,否則mysql會在wait_timeout的時間後關閉連接,然而連接池還認為該連接可用,這樣就會產生以上圖內的錯誤。
MySQL :
interactive_timeout=XX
The number of seconds the server waits for activity on an interactive connection before closing it.
wait_timeout=XX
The number of seconds the server waits for activity on a noninteractive connection before closing it.
DBCP
timeBetweenEvictionRunsMillis 每毫秒檢查一次連接池中閒置的連接(spec :The number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no idle object evictor thread will be run.)預設是-1
minEvictableIdleTimeMillis 連接池中連接可閒置的時間(spec:The minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any). )
上面兩個設定要一起使用,意思是說每timeBetweenEvictionRunsMillis毫秒檢查一次連接池中空閒的連接,把空閒時間超過 minEvictableIdleTimeMillis毫秒的連接斷開,直到連接池中的連接數到minIdle為止
mysql >show variables like '%timeout%';
回覆刪除可以確認預設就是28800/60/60 = 8 小時
jdbc:mysql://localhost:3306/XX??autoReconnect=true
回覆刪除在5.0已經沒用了
java.net.SocketException: Broken pipe
回覆刪除也是這種解法?