当前位置: 首页 > >

Cannot get a connection, pool exhausted½â¾ö°ì·¨

发布时间:

http://blog.163.com/it_message/blog/static/8892051200908102032653/


?


Á¬½Ó³Ø£¨Tomcat+oracle£©,ÔËÐÐÒ»¶Îʱ¼äºó¾Í»á³öÏÖ Cannot get a connection, pool exhaustedÕâÑùµÄÒì³£¡£ÆäʵÕâ¸öÎÊÌâºÜ¼òµ¥¾ÍÊÇÊý¾Ý¿âconnection¶ÔÏóÓþ¡ÁË¡£


½â¾öµÄ°ì·¨ÓÐ3¸ö


1Ö*ô·þÎñÆ÷


2ÔÚcontent.xmlÖУ¬½«maxActiveÉèÖÃΪÁ㣬»òÕßµ÷¸ßËüµÄÖµ


3ÔÚÄãµÄ³ÌÐòÖÐÕýÈ·¹Ø±Õconnections ÕâÀïÓÐÒ»µãҪעÒâÒª°Ñ¹Ø±ÕµÄÓï¾äдÔÚfinallyÖУ¬Èç¹ûÄãдÔÚtry{}ÖгöÏÖÒì³£µÄ»°ÊÇÎÞ·¨ÕýÈ·¹Ø±ÕµÄ¡£


ÒªÏóÕâÑù


} catch (SQLException e) {


/** Exception handling **/


} finally {


try {


if (stmt != null)


stmt.close();


if (dbConnection != null)


dbConnection.close();


} catch (SQLException e) {


/** Exception handling **/


}


}


µ±È»Õâ3¸ö·½·¨ÀïÇ°Á½¸ö²¢²»ÄÜ´Ó¸ù±¾ÉϽâ¾öÄãµÄÎÊÌ⣬ËùÒÔ»¹ÊÇÒªºÃºÃÑо¿ÄãµÄ³ÌÐò£¬Ò»¶¨Òª½«ÓÃÍêµÄconnection·Å»Øµ½³ØÖС£


1 ÎÊÌâÃèÊö


Web³ÌÐòÔÚtomcat¸Õ¿ªÊ¼ÔËÐÐʱËٶȺܿ죬µ«¹ýÒ»¶Îʱ¼äºó·¢ÏÖËٶȱäµÃºÜÂý¡£


¼ì²éÈÕÖ¾Êä³ö£¬·¢ÏÖÒì³£ÈçÏÂ:


org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted, cause:


java.util.NoSuchElementException: Timeout waiting for idle object


ͬʱÔÚSQLServerʼþ̽²éÆ÷Öз¢ÏÖ£¬Ã¿Ö´ÐÐÒ»´ÎsqlÓï¾ä¶¼Òª²úÉúAudit loginʼþ£¬Óï¾äÖ´Ðкó²úÉú


Audit logoutʼþ¡£ËµÃ÷ÿһ´Îtomcat¶¼ÊÇÖØдò¿ªÐµÄÁ¬½Ó¡£


2 ÎÊÌâ½â¾ö


tomcat µÄÊý¾ÝÔ´¶¨ÒåÌṩÁËÈý¸ö²ÎÊý£º


a. Èç¹ûÉèΪtrueÔòtomcat×Ô¶¯¼ì²é»Ö¸´ÖØÐÂÀûÓã¬Ã»ÓÐÕý³£¹Ø±ÕµÄConnection.£¨Ä¬ÈÏÊÇfalse£©



removeAbandoned


true



b. É趨Á¬½ÓÔÚ¶àÉÙÃëÄÚ±»ÈÏΪÊÇ·ÅÆúµÄÁ¬½Ó£¬¼´¿É½øÐлָ´ÀûÓá£



removeAbandonedTimeout


60



c. Êä³ö»ØÊÕµÄÈÕÖ¾£¬¿ÉÒÔÏêϸ´òÓ¡³öÒì³£´Ó¶ø·¢ÏÖÊÇÔÚÄÇÀï·¢ÉúÁËй©



logAbandoned


true



?


---------------------------------------------------------------------------------------------------------------------------------------


?maxActive¡¢maxIdle ½¨ÒéÉèÖà maxActive="300" maxIdle="50"


maxActive ÉèÖÃÔÚ300-1000Ö®¼ä


maxIdle?? ÉèÖÃÔÚ 20-100 Ö®¼ä


»¹ÓоÍÊÇÔÚ³ÌÐòµÄ finally ÀïÃæÒª¹Ø±Õ Connection


ÀýÈ磺 DbHelper.closedAll(rs, ps, conn);


?


maxIdle£¬×î´ó¿ÕÏÐÊý£¬Êý¾Ý¿âÁ¬½ÓµÄ×î´ó¿ÕÏÐʱ¼ä¡£³¬¹ý¿ÕÏÐʱ¼ä£¬Êý¾Ý¿âÁ¬?
½Ó½«±»±ê¼ÇΪ²»¿ÉÓã¬È»ºó±»ÊÍ·Å¡£ÉèΪ0±íʾÎÞÏÞÖÆ¡£?
MaxActive£¬Á¬½Ó³ØµÄ×î´óÊý¾Ý¿âÁ¬½ÓÊý¡£ÉèΪ0±íʾÎÞÏÞÖÆ¡£?
maxWait £¬×î´ó½¨Á¢Á¬½ÓµÈ´ýʱ¼ä¡£Èç¹û³¬¹ý´Ëʱ¼ä½«½Óµ½Òì³£¡£ÉèΪ-1±íʾ?
ÎÞÏÞÖÆ¡£?



תÔØÓÚ:https://www.cnblogs.com/lteal/p/5896171.html



友情链接: 传奇百科网 招聘百科网 非凡百科网 游艇百科网 口红百科网 创业百科网 软木百科网