java.lang.OutOfMemoryError:GC overhead limit exceeded c3p0 mysql connection版本 Druid HttpClient正確關閉

1, 配置參數可以加上 增加參數,-XX:-UseGCOverheadLimit

2, mysql connection 版本如果小於5.1.10 有個內存bug

3,c3p0 連接池等數據庫連接池,如果程序內部沒處理好, 可能會出現連接一直存在,最後連接不夠, 可以用開源的阿里巴巴 mysql連接 Druid, 設置removeAbandoned=true,removeAbandonedTimeout=600(10分鐘), 

Druid可能是現在最好的數據庫連接池~~~

4,HttpClient (Apache的4.x及以上)要正確關閉get/post,和entity

HttpResponse resp = null;
try {
resp = client.execute(httpGet);
if (resp.getStatusLine().getStatusCode() == 200) {
isPostBackSucc = true;
}
} catch (Throwable e) {
logger.error("error", e);
} finally {
try {
httpGet.abort();//這裏要調用
} catch (Exception e) {
}
if (resp != null) {
try {
EntityUtils.consumeQuietly(resp.getEntity());//這裏要關閉
} catch (Exception e) {
}
}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章