TOMCAT/APACHE
2017.05.29 / 10:56

[Common DBCP] ¼³Á¤ ¹× ¿¹ java.sql.SQLRecoverableException: IO Error: Connection Timeout

½Å´Ïºñ
Ãßõ ¼ö 308

 DBCP ¹®Á¦ ÇØ°á±â 

1. ¹®Á¦»óȲ : 
- ¿ÀÇÂÇÏ°í Áö±Ý±îÁö Ä¿³Ø¼Ç ¹®Á¦°¡ ¾ø¾úÀ¸³ª, ¿äûÀÌ ÇöÀç 3¹è ÀÌ»ó Áõ°¡ÇÏ¿© Ä¿³Ø¼Ç ¹®Á¦°¡ ¹ß»ýÇÏ°í ÀÖ¾úÀ½. 
- ¹ß»ý¹®Á¦ : Cannot get a connection, pool error Timeout waiting for idle object °ü·Ã ¿¹¿Ü°¡ °è¼ÓÇؼ­ ¹ß»ýÇÔ. 
- DBA·Î ºÎÅÍ ³Ê¹«¸¹Àº Ä¿³Ø¼Ç ¿äûÀÌ µé¾î¿Â´Ù´Â º¸°í¸¦ ¹ÞÀ½ 

2. ºÐ¼® : 
- Ä¿³Ø¼ÇÀ» ´ë±âÇÏ´Â ½Ã°£µ¿¾È Ä¿³Ø¼ÇÀ» ȹµæÇÏÁö ¸øÇؼ­ ¹ß»ýÇÑ ¿À·ù 
- Áï, maxWaitMillis¸¦ ³Ñ¾î¼­µµ Ä¿³Ø¼ÇÀ» ȹµæÇÏÁö ¸øÇÏ´Â ¹®Á¦°¡ ¹ß»ý. 

3. Ä¿³Ø¼Ç ¼³Á¤ È®ÀÎ : 
BEFORE : 
maxWait=600
slowQueryTime=300
initialSize=5
maxActive=30
maxIdle=20
minIdle=5
useStatementCache=true
statementCacheSize=250
testOnBorrow=false
testOnReturn=false
testWhileIdle=false
timeBetweenEvictionRunsMillis=600000
minEvictableIdleTimeMillis=3600000
queryTimeout=0
useSqlLogForamt=false
connectionProperties=oracle.net.CONNECT_TIMEOUT=5000;oracle.jdbc.ReadTimeout=60000
# beta
beta.queryTimeout=7
beta.useSqlLogForamt=false


--> »ó±â ¼³Á¤Àº ÇϳªÀÇ Ä¿³Ø¼ÇÀÌ 1½Ã°£µ¿¾È idle·Î µÇ¾î ÀÕÀ¸¸é Ä¿³Ø¼ÇÀÌ notValidÇÑ °ÍÀ¸·Î ÆÇ´ÜÇÏ´Â °ÍÀÌ´Ù. 
--> Ãʱâ maxActive´Â 30À¸·Î ¼³Á¤µÇ¾ú°í, maxIdle°ªÀº 20À¸·Î ¼³Á¤µÇ¾ú´Ù. 

#Áï »ó±â ¼³Á¤À» ÅëÇؼ­ Ä¿³Ø¼ÇÀÌ 20°³ ÀÌ»óÀÌ µÇ´Â°æ¿ì Ä¿³Ø¼ÇÀ» ¸Î°í, »ç¿ëÈÄ¿¡ ¹Ù·Î closeÇÑ´Ù. ±×¸®°í ¿äûÀÌ ÇÊ¿äÇÑ°æ¿ì ´Ù½Ã connectionÀ» ¸Î±â À§Çؼ­ DBÁ¢±ÙÀ» °è¼ÓÇÏ´Â »óȲÀÌ µÈ´Ù. 

#¶ÇÇÑ ½ÇÁ¦ IdleÇÑ Ä¿³Ø¼ÇÀº 1½Ã°£ÀÌ Áö³ª¸é evict µÇ¾î Àç Á¢¼ÓÀÌ ÇÊ¿äÇÑ »óȲÀÌ µÈ´Ù. 

AFTER : ¼öÁ¤ÀÌÈÄ 

maxWait=600
slowQueryTime=300

initialSize=5
maxActive=30
maxIdle=30
minIdle=5
useStatementCache=true
statementCacheSize=250
testOnBorrow=false
testOnReturn=false
testWhileIdle=true
validationQuery=SELECT 1 FROM DUAL
timeBetweenEvictionRunsMillis=150000
minEvictableIdleTimeMillis=-1
numTestsPerEvictionRun=5
queryTimeout=0
useSqlLogForamt=false
connectionProperties=oracle.net.CONNECT_TIMEOUT=5000;oracle.jdbc.ReadTimeout=60000
# beta
beta.queryTimeout=7
beta.useSqlLogForamt=false
- maxActive¿Í maxIdle°ªÀ» °°°Ô ¼³Á¤ÇÏ¿´´Ù. Áï, Ä¿³Ø¼ÇÁ¦ÇÑÀ» ¹Ì¸® ¼³Á¤Çصΰí, »ç¿ëÈÄ ¹Ý³³ÇÏ´Â ÀÏÀÌ ¾øµµ·Ï ¼³Á¤ÇÏ¿´´Ù. 
- »ó±â ¼³Á¤Àº idle»óÅÂÀÇ Ä¿³Ø¼ÇÀ» ´ë»óÀ¸·Î validationQuery¸¦ º¸³»°Ô ¼³Á¤ÇÏ¿´´Ù. 
- ¶ÇÇÑ Ä¿³Ø¼Ç °Ë»ç½Ã°£À» 150000À¸·Î ¼³Á¤ÇÏ¿´´Ù. ¸Å 150000¸¶´Ù Ä¿³Ø¼Ç °Ë»ç¸¦ ½ÃÀÛÇÑ´Ù. 
- minEvictableIdleTimeMillis=-1·Î ¼³Á¤ÇÏ¿© Ç®¿¡ ÀÖ´Â Ä¿³Ø¼ÇÀº ¹«Á¶°Ç »ì¾Æ ÀÖ´Ù°í °¡Á¤ÇÑ´Ù.
- numTestsPerEviceionRun=5·Î ¼³Á¤ÇÏ¿© Çѹø  Ä¿³Ø¼Ç valid ÇÒ¶§¹Ù´Ù 5°³¸¦ °Ë»çÇϵµ·Ï ÁöÁ¤ÇÏ¿´´Ù. 

4. °á°ú 
- Ä¿³Ø¼ÇÀ» ±â´Ù¸®´Ù°¡ ŸÀӾƿô µÇ´Â Çö»óÀÌ »ç¶óÁ³´Ù.
- ¸Å ¼ø°£¸¶´Ù Ä¿³Ø¼ÇÀ» °è¼Ó ¸Î´Â Çö»óÀÌ »ç¶óÁ³´Ù. 

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

Apache Common DBCP

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

Common DBCP¶õ :

Common DBCP´Â Apache CommonÀÇ ÇÁ·ÎÁ§Æ® ÇÏÀ§¿¡ ÀÖ´Â µ¥ÀÌÅͺ£À̽º Ä¿³Ø¼Ç Ç®À» Á¦°øÇϱâ À§ÇÑ ±â´ÉÀ» Á¦°øÇÑ´Ù.


DB Æ®·£Àè¼ÇÀ» ó¸®Çϱâ À§Çؼ­ °¡Àå ºñ¿ëÀÌ ¸¹ÀÌ µå´Â °ÍÀº µ¥ÀÌÅͺ£À̽º¿Í Ä¿³Ø¼ÇÀ» ½Å±Ô·Î »ý¼ºÇÏ´Â °úÁ¤À¸·Î DBCP¸¦ ÀÌ¿ëÇÏ¸é »ý¼ºµÈ Ä¿³Ø¼ÇÀ» pool¿¡ ³Ö°í Àç»ç¿ëÇÏ¿© ¼º´ÉÀ» ±Ø´ëÈ­ ÇÏ´Â ¹æ¹ýÀ» Á¦°øÇÑ´Ù.

DBCP2ÀÇ Æ¯Â¡ : 
common-dbcp2 ´Â common-pool2 ÆÐÅ°Áö ³»¿¡ Æ÷ÇԵǾî ÀÖÀ¸¸ç, Java 7 À̻󿡼­ µ¿ÀÛÇÑ´Ù. (JDBC 4.1)

DBCP2´Â Commons Pool2¸¦ ±â¹ÝÀ¸·Î ÇÑ´Ù. 
±âÁ¸ DBCPº¸´Ù ¼º´ÉÀÌ ´õ ÁÁ¾ÆÁ³´Ù. 
JMXÀ» Áö¿øÇÏ¿© DBCP 1.x¹öÁ¯¿¡ ºñÇؼ­ ´õ ¸¹Àº ±â´ÉÀ» Á¦°øÇÑ´Ù. 


DBCP Configuration : 

1. ±âº» ¼³Á¤ : 
1.1 username : Ä¿³Ø¼ÇÀ» »ý¼ºÇϱâ À§ÇÑ DB»ç¿ëÀÚ À̸§
1.2 password : Ä¿³Ø¼ÇÀ» »ý¼ºÇϱâ À§ÇÑ DB»ç¿ëÀÚ ºñ¹Ð¹øÈ£
1.3 url      : Ä¿³Ø¼ÇÀ» »ý¼ºÇϱâ À§ÇÑ DB URL
1.4 driverClassName : »ç¿ëµÉ JDBCÀÇ Ç® Àڹ٠Ŭ·¡½º À̸§ 
1.5 connectionProperties : »õ·Î¿î Ä¿³Ø¼Ç »ý¼ºÀ» À§Çؼ­ JDBC µå¶óÀ̹ö¿¡ Àü´ÞÇÒ ¼Ó¼ºµéÀ» ÀǹÌÇÑ´Ù. 
   [propertyName=property;]* ÀÇ Çü½ÄÀ» °¡Áø´Ù. 

2. Æ®·£Àè¼Ç °ü·Ã ¼³Á¤ : 
2.1 defaultAutoCommit 
- ±âº»°ª : driver default
- ¼³¸í : Ç®¿¡ »ý¼ºµÈ Ä¿³Ø¼ÇÀÇ auto-commit»óŸ¦ ¼³Á¤ÇÑ´Ù. ¼³Á¤À» ÇÏÁö ¾ÊÀ¸¸é setAutoCommit¸Þ¼Òµå°¡ È£ÃâµÇÁö ¾Ê´Â´Ù. 

2.2 defaultReadOnly 
- ±âº»°ª : driver default
- ¼³¸í : Ç®¿¡ ÀÇÇؼ­ »ý¼ºµÈ Ä¿³Ø¼ÇÀÇ read-only»óŸ¦ ¼³Á¤ÇÑ´Ù. ¼³Á¤À» ÇÏÁö ¾ÊÀ¸¸é setReadOnly¸Þ¼Òµå°¡ È£ÃâµÇÁö ¾Ê´Â´Ù. (Infomix¿Í °°Àº ¸î¸î µå¶óÀ̹ö´Â ÀÌ ¼³Á¤À» Áö¿øÇÏÁö ¾Ê´Â´Ù.)

2.3 defaultTransactionIsolation
- ±âº»°ª : driver default
- ¼³¸í : ±âº» Æ®·£Àè¼Ç IsolationÀ» ÁöÁ¤ÇÑ´Ù. 
NONE
READ_COMMITTED
READ_UNCOMMITTED
REPEATABLE_READ
SERIALIZABLE

2.4 defaultCatalog
- ±âº»°ª : ¾øÀ½
- ¼³¸í : Ç®¿¡ »ý¼ºµÈ Ä¿³Ø¼ÇÀÇ ±âº» Ä«Å»·Î±×¸¦ ¼³Á¤ÇÑ´Ù. 

2.5 cacheState 
- ±âº»°ª : true
- ¼³¸í : true·Î ¼³Á¤Çϸé Ç®µÈ Ä¿³Ø¼ÇÀº ù¹ø° Àбâ¿Í ¾²±â¸¦ ¼öÇàÇÒ¶§ ¼³Á¤µÈ readOnly¿Í autoCommit °ªÀ» ij½ÃÇصΰí ÀÌÇÏ ¾²±â½Ã¿¡ À̸¦ Àû¿ëÇÑ´Ù. ¸¸¾à Ä¿³Ø¼ÇÀÌ Á÷Á¢ Á¢±Ù µÇ¾î¾ß Çϰųª readOnly³ª autoCommit ¼³Á¤ÀÌ Ä³½Ã¿¡¼­ º¯°æÀÌ µÇ´õ¶óµµ ÇöÀç Ä¿³Ø¼Ç¿¡´Â ¹Ý¿µµÇÁö ¾Ê´Â´Ù. ij½ÌÀ» ÇÏÁö ¾Ê°íÀÚ ÇÏ´Â ÄÉÀ̽º¿¡¼­´Â ÀÌ °ªÀ» false·Î µÎ¸é µÈ´Ù. 

2.6 defaultQueryTimeout 
- ±âº»°ª : null
- ¼³¸í : ÀÌ°ªÀÌ nullÀÌ ¾Æ´Ñ°æ¿ì ¿©±â¿¡ ¼³Á¤µÈ Á¤¼öÇüÀÇ °ªÀº Ç®¿¡ ÀÇÇؼ­ °ü¸®µÇ´Â Ä¿³Ø¼ÇÀ¸·Î ºÎÅÍ »ý¼ºµÈ ½ºÅ×ÀÌÆ® ¸ÕÆ®¿¡ »ç¿ëµÉ Äõ¸® ŸÀӾƿôÀ» ÁöÁ¤ÇÏ°Ô µÈ´Ù. nullÀÇ Àǹ̴ driverÀÇ ±âº»°ªÀ» »ç¿ëÇÏ°Ú´Ù´Â ÀǹÌÀÌ´Ù. 

2.7. enableAutocommitOnReturn
- ±âº»°ª : null
- ¼³¸í : true·Î ¼³Á¤Çϸé Ç®ÀÌ Ä¿³Ø¼ÇÀ¸·Î ¹ÝȯµÉ¶§ Connection.setAutoCommit(true)ÀÎÁö üũµÇ°í, ÇØ´ç°ªÀ¸·Î ¼³Á¤µÈ´Ù. ¸¸¾à auto commit°¡ falseÀΰæ¿ì¶ó¸é true·Î º¯°æ ¼³Á¤µÈ´Ù. 

2.8 rollbackOnReturn
- ±âº»°ª : true
- ¼³¸í : trueÀÇ Àǹ̴ Ǯ·Î Ä¿³Ø¼ÇÀÌ ¹ÝȯµÉ¶§ ·Ñ¹éÀÌ ¼öÇàµÈ´Ù. ´Ü auto commitÀÌ falseÀÌ°í, Ä¿³Ø¼ÇÀÌ read only¸ðµå°¡ ¾Æ´Ï¾î¾ßÇÑ´Ù. 


3. Ä¿³Ø¼Ç °³¼ö ¼³Á¤ 
3.1 initialSize 
- ±âº»°ª : 0
- ¼³¸í : Ç®ÀÌ ½ÃÀ۵ɶ§ Ãʱ⿡ ¼³Á¤µÉ Ä¿³Ø¼ÇÀÇ °³¼ö¸¦ ÁöÁ¤ÇÑ´Ù. 1.2¹öÁ¯ºÎÅÍ Áö¿ø

3.2 maxTotal 
- ±âº»°ª : 8
- ¼³¸í : active connectionÀÇ ÃÖ´ë °³¼ö¸¦ ÁöÁ¤ÇÑ´Ù. ÀÌ°ÍÀº µ¿½Ã¿¡ Ç®¿¡ ÇÒ´çµÉ ¼ö ÀÖ´Â ÃÖ´ë Ä¿³Ø¼ÇÀÇ °³¼öÀÌ´Ù. À½¼ö·Î ¼³Á¤Çϸé Á¦ÇÑÀÌ ¾ø´Ù´Â Àǹ̰¡ µÈ´Ù. 

3.3 maxIdle
- ±âº»°ª : 8
- ¼³¸í : Ç®¿¡¼­ idle·Î ³²¾Æ ÀÕÀ» ¼ö ÀÖ´Â ÃÖ´ë °³¼öÀÌ´Ù. ÀÌ °ªº¸´Ù ³Ñ´Â Ä¿³Ø¼ÇÀº ¸±¸®Áî µÈ´Ù. À½¼ö´Â Á¦ÇÑÀÌ ¾ø´Ù´Â ÀǹÌÀÌ´Ù. 

3.4 minIdle
- ±âº»°ª : 0
- ¼³¸í : Ç®¿¡ idle·Î ³²¾ÆÀÖ´Â ÃÖ¼Ò °³¼öÀÌ´Ù. Áï Ç®¿¡ ³²¾Æ ÀÖÀ» ¼ö ÀÖ´Â ÃÖ¼Ò Ä¿³Ø¼Ç °³¼öÀÌ´Ù. 

3.5 maxWaitMillis
- ±âº»°ª : idenfinitely
- ¼³¸í : ÃÖ´ë ¹Ð¸®¼¼ÄÁÀ» ÁöÁ¤ÇÏ´Â °ÍÀ¸·Î Ä¿³Ø¼ÇÀ» ¾ò±â À§ÇØ ±â´Ù¸®´Â ½Ã°£ÀÌ´Ù. Ä¿³Ø¼ÇÀÌ ¸ðµÎ ´Ù ¾²°í ÀÖ´Â »óÅ¿¡¼­ ½º·¹µå°¡ ÇϳªÀÇ Ä¿³Ø¼ÇÀ» ¾ò±â À§ÇØ ´ë±âÇÏ´Â ½Ã°£ÀÌ´Ù. -1·Î ¼³Á¤ÇÏ¸é ¹«ÇÑÁ¤ ±â´Ù¸°´Ù. 

NOTE : 
- ¸¸¾à ¸Å¿ì ¹«°Å¿î ½Ã½ºÅÛ¿¡¼­ maxIdle°ªÀ» ³Ê¹« ÀÛ°Ô ¼³Á¤Çϸé, Ä¿³Ø¼ÇÀ» ´Ý°í³ª¼­ ¹Ù·Î Áï½Ã Ä¿³Ø¼ÇÀ» ¿¬°áÇÏ´Â ÀÏÀÌ ¹ß»ýÇÒ ¼ö ÀÖ´Ù. ÀÌ °á°ú´Â Ä¿³Ø¼ÇÀ» ¼ø°£¸¸ ÀÌ¿ëÇÏ°í Ä¿³Ø¼ÇÀ» ¿©´Â ½Ã°£º¸´Ù ´Ý´Â½Ã°£ÀÌ Âª°Ô µÇ´Â Çö»óÀÌ ³ªÅ¸³­´Ù. ÀÌ°ÍÀº idle Ä¿³Ø¼ÇÀÇ °³¼ö°¡ maxIdle±îÁö Áõ°¡ÇÏ´Â Çö»óÀ» ¿øÀÎÀÌ µÈ´Ù. 
- ¹«°Å¿î ½Ã½ºÅÛ¿¡¼­ °¡Àå ÁÁÀº maxIdle °ªÀº ½Ã½ºÅÛ¸¶´Ù ´Ù¸¦ °ÍÀÌ´Ù. ±×·¯³ª ±âº»°ªÀº ÁÁÀº ½ÃÀÛ Æ÷ÀÎÆ®°¡ µÈ´Ù. 

4. Ä¿³Ø¼Ç À¯Áö¸¦ À§ÇÑ ¼³Á¤ 
4.1 validationQuery
- ±âº»°ª : ¾øÀ½
- ¼³¸í : validationQuery´Â Ç®¿¡ Ä¿³Ø¼ÇÀ» ¹ÝȯÇϱâ ÀüÀ̳ª, Ç®À» ȹµæÇϱâ Àü¿¡ Ä¿³Ø¼ÇÀÌ validÇÑÁö¸¦ °Ë»çÇÑ´Ù. À̸¦ ÁöÁ¤ÇÏ°íÀÚ Çϴ°æ¿ì selectÄõ¸®´Â ¹Ýµå½Ã 1·Î¸¸ ¹ÝȯÇϵµ·Ï ¼³Á¤ÇؾßÇÑ´Ù. ¸¸¾à À̸¦ ÁöÁ¤ÇÏÁö ¾ÊÀ¸¸é Ä¿³Ø¼ÇÀº isValid()¸Þ¼Òµå¸¦ ÅëÇؼ­ validÇÑÁö °Ë»çÇÏ°Ô µÈ´Ù. 

4.2 validationQueryTimeout
- ±âº»°ª : no timeout

- ¼³¸í : Ä¿³Ø¼Ç validation Äõ¸®°¡ ½ÇÆÐÇϱâ Àü±îÁö ½Ã°£À» ÀǹÌÇÑ´Ù. ¸¸¾à ¾ç¼ö·Î ¼³Á¤Çϸé setQueryTimeout¸Þ¼Òµå¸¦ ÅëÇؼ­ ¼³Á¤ÀÌ µÇ¸ç, Statement¸¦ ÅëÇؼ­ validationÄõ¸®°¡ ¼öÇàµÈ´Ù.

4.3 testOnCreate
- ±âº»°ª : false
- ¼³¸í : »ý¼ºµÈ ÀÌÈÄ¿¡ °´Ã¼°¡ validateµÇ¾ú´ÂÁö ¿©ºÎ¸¦ ³ªÅ¸³½´Ù. ¸¸¾à °´Ã¼°¡ validate¿¡¼­ ½ÇÆÐÇÑ°æ¿ì °´Ã¼ »ý¼ºÀº ½ÇÆа¡ µÈ´Ù.

4.4 testOnBorrow
- ±âº»°ª : true
- ¼³¸í : Ç®¿¡¼­ Ä¿³Ø¼ÇÀ» ¾ò¾î¿À±âÀü¿¡ °´Ã¼°¡ validÇÑÁö °Ë»çÇÑ´Ù. ¸¸¾à °´Ã¼°¡ validate¿¡¼­ ½ÇÆÐÇϸé, Ç®·Î ºÎÅÍ °´Ã¼¸¦ dropÇϸç, ´Ù¸¥ °´Ã¼¸¦ ¾ò±âÀ§ÇØ ½ÃµµÇÑ´Ù.

4.5 testOnReturn
- ±âº»°ª : false
- ¼³¸í : Ç®·Î °´Ã¼¸¦ ¹ÝȯÇϱâ Àü¿¡ validatedµÈ °ªÀÎÁö °Ë»çÇÑ´Ù.

4.6 testWhileIdle
- ±âº»°ª : false
- ¼³¸í : idle object evictor¿¡ ÀÇÇؼ­ °ËÁõµÇ¾îÁö¸ç, ¸¸¾à °´Ã¼°¡ °ËÁõ¿¡¼­ false°¡ µÇ¸é pool·Î ºÎÅÍ µå·ÓÇÑ´Ù.

4.7 timeBetweenEvictionRunsMills
- ±âº»°ª : -1
- ¼³¸í : idle object evictor½º·¹µåÀÇ ½ÇÇà ÁֱⰣ°ÝÀ» ¼³Á¤ÇÑ´Ù. ¾ç¼ö °ªÀÌ ¾Æ´Ñ°æ¿ì¿¡´Â idle object evictor¸¦ ½ÇÇàÇÏÁö ¾Ê´Â´Ù.

4.8 numTestsPerEvictionRun
- ±âº»°ª : 3
- ¼³¸í : idle object evictor ½º·¹µå°¡ ¸Å¹ø ½ÇÇàÇÒ¶§ °Ë»çÇÒ °´Ã¼ÀÇ °³¼ö¸¦ ÁöÁ¤ÇÑ´Ù.

4.9 minEvictableIdleTimeMillis
- ±âº»°ª : 1000 * 60 * 30
- ¼³¸í :Ç®¿¡ °´Ã¼°¡ idle»óÅ·ΠÀÖÀ» ¼ö ÀÖ´Â ÃÖ¼ÒÇÑÀÇ ½Ã°£°ªÀ» ÁöÁ¤ÇÑ´Ù.

4.10 softMiniEvictableIdleTimeMillis
- ±âº»°ª : -1
- ¼³¸í : idle collection evictor¿¡ ÀÇÇؼ­ Á¦°ÅµÇ±â Àü¿¡ Ç®¿¡ idle »óÅ·Π³²¾ÆÀÖÀ» ¼ö ÀÖ´Â ½Ã°£À» ÀǸ¶Èù´Ù. ÀÌ°ÍÀº Ãß°¡ÀûÀÎ »óȲÀ» ÇÔ²² °í·ÁµÇ¸ç Àû¾îµµ "minIdle"Ä¿³Ø¼ÇÀ» ³²±âµµ·Ï ÇÑ´Ù. miniEvictableIdleTimeMillis°¡ ¾ç¼ö·Î ¼³Á¤ÀÌ µÇ¸é minEvictableIdleTimeMillis´Â ¿ì¼± ¼öÇàµÈ´Ù. ÀÌ°ÍÀº idle connectionsµéÀÌ evictor¿¡ ÀÇÇؼ­ ¹æ¹®µÇ¾îÁú¶§ idle timeÀº ¿ì¼± miniEvictableIdleTimeMillis¿¡ ´ëÇؼ­ ºñ±³µÇ¾îÁø´Ù. (Ç®¿¡ ÀÖ´Â idle Ä¿³Ø¼ÇÀÇ ¼ö¸¦ °í·ÁÇÏÁö ¾Ê´Â´Ù.) ±×¸®°í softMinEvictableIdleTimeMillis¿¡ ´ëÇؼ­ ¼öÇàÀÌ µÇ¸ç minIdle constraint¸¦ Æ÷ÇÔÇÑ´Ù.

4.11 maxConnLifetimeMillis
- ±âº»°ª : -1
- ¼³¸í : Ä¿³Ø¼ÇÀÇ ÃÖ´ë ¶óÀÌÇÁŸÀÓÀ» ÁöÁ¤ÇÑ´Ù. ÀÌ °ªÀÌ Áö³ª°Ô µÇ¸é ´ÙÀ½¹ø activation, passivation,ȤÀº validationÅ×½ºÆ®¿¡¼­ ½ÇÆÐÇÏ°Ô µÈ´Ù. zeroÀÇ °ª ȤÀº ´õ ÀûÀº °ªÀº ¶óÀÌÇÁ ŸÀÓÀÌ ¾ø´Â °ÍÀ» ÀǹÌÇÑ´Ù.

4.12 logExpiredConnections
- ±âº»°ª : true
- ¼³¸í : ·Î±× ¸Þ½ÃÁö·Î maxConnLifetimeMillis¸¦ ÃÊ°úÇÑ °æ¿ì¿¡ Ä¿³Ø¼ÇÀÌ ´ÝÇûÀ½À» ·Î±×·Î ³²±ä´Ù. ÀÌ ¼Ó¼ºÀ» false·Î ¼³Á¤ÇÏ¿© ÀͽºÆÄÀ̾îµÈ Ä¿³Ø¼Ç·Î±ëÀ» ¸·µµ·Ï ¼³Á¤ÇÒ ¼ö ÀÖ´Ù.

4.13 connectionInitSqls
- ±âº»°ª : null
- ¼³¸í : SQL statementsÀÇ Ä÷º¼ÇÀ¸·Î ¹°¸®Àû Ä¿³Ø¼ÇÀÇ ÃÖ±âÈ­¿¡ »ç¿ëµÇ¾îÁø´Ù. ÀÌ°ÍÀº Ä¿³Ø¼ÇÀÌ Ã³À½ »ý¼ºµÉ¶§ ÀÛ¿ëÇÑ´Ù. ÀÌ ½ºÅ×ÀÌÆ®¸ÕÆ®´Â ¿ÀÁ÷ Çѹø¸¸ ¼öÇàµÈ´Ù. ¼³Á¤µÈ Ä¿³Ø¼Ç ÆÑÅ丮°¡ Ä¿³Ø¼ÇÀ» »ý¼ºÇÑ´Ù.

4.14 lifo
- ±âº»°ª : true
- ¼³¸í : True·Î ¼³Á¤Çϸé borrowObject¸¦ ÇÏ¿´À»¶§ °¡Àå ÃÖ±Ù¿¡ »ç¿ëµÈ (Áï ¸¶Áö¸·¿¡ ÀԷµÈ) Ä¿³Ø¼ÇÀ» ¹ÝȯÇÑ´Ù. (¸¸¾à idle Ä¿³Ø¼ÇÀÌ °¡´ÉÇÑ °æ¿ì¿¡ °¡´ÉÇÏ´Ù.) False´Â Ç®Àº FIFO Å¥·Î µ¿ÀÛÇÑ´Ù. Ä¿³Ø¼ÇµéÀº Ç®¿¡ µé¾î¿Â ¼ø¼­´ë·Î Ç®¿¡¼­ Ä¿³Ø¼ÇÀ» ¹ÝȯÇÑ´Ù.

5. SQL¹®Àå¿¡ ´ëÇÑ Ç® ¼³Á¤ 
5.1 poolPreparedStatements :
- ±âº»°ª : false
- ¼³¸í : ÇöÀç Ç®À» À§ÇÑ statement Ç®¸µÀ» ¼³Á¤ÇÑ´Ù.

5.2 maxOpenPreparedStatements
- ±âº»°ª : undefined
- ¼³¸í : ÃÖ´ë °³¼öÀÇ ¿ÀÇ ½ºÅ×ÀÌÆ®¸ÕÆ®¸¦ ÀǹÌÇÑ´Ù. ÀÌ°ÍÀº statement pool¿¡ µ¿½Ã¿¡ ÇÒ´çµÉ ¼ö ÀÖ´Â °ªÀ¸·Î, À½¼ö¸¦ ÁöÁ¤Çϸé Á¦ÇÑÀÌ ¾øÀ½À» ÀǹÌÇÑ´Ù.

- »ó±â ¼³Á¤Àº ´ÙÀ½ ¸Þ¼Òµå¸¦ ÀÌ¿ëÇÏ´Â °æ¿ì Ç®¿¡ ÇÒ´çµÈ´Ù.
-- public PreparedStatement prepareStatement(String sql)
-- public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)

NOTE : 
- Ä¿³Ø¼ÇÀÌ ´Ù¸¥ statements¸¦ À§Çؼ­ ¸î¸îÀÇ ¸®¼Ò½º¸¦ ³²°Ü µÎ¾ú´ÀÁö È®ÀÎÇ϶ó. Pooling PreparedStatements´Â µ¥ÀÌÅͺ£À̽º¿¡¼­ ÇØ´ç Ä¿¼­¸¦ ¿ÀÇÂÇ× »óÅ·ΠµÑ¼ö ÀÖ´Ù. ÀÌ·±°æ¿ì PoolingÀÌ Ä¿¼­¸¦ ¸ðµÎ ¼ÒºñÇØ ¹ö¸± ¼ö ÀÖ´Ù. ƯÈ÷ maxOpenPreparedStatements°¡ ±âº»(Á¦ÇѾøÀ½)À¸·Î ¼³Á¤µÈ°æ¿ì ±×¸®°í ¾îÇø®ÄÉÀ̼ÇÀÌ Å« ¼öÀÇ ¼­·Î´Ù¸¥ PreparedStatements¸¦ ÇϳªÀÇ Ä¿³Ø¼Ç¿¡¼­ ¿­°í ÀÖ´Â »óŶó¸é ´õ¿í ÁÖÀÇÇؾßÇÑ´Ù. ÀÌ·¯ÇÑ ¹®Á¦¸¦ ÇÇÇϱâ À§Çؼ­´Â maxOpenPreparedStatements´Â ÇϳªÀÇ Ä¿³Ø¼Ç´ç ¿­¼ö ÀÖ´Â ÃÖ´ë Ä¿¼­ÀÇ ¼öº¸´Ù ÀÛÀº °ªÀ» °¡Áöµµ·Ï ¼³Á¤ÇؾßÇÑ´Ù.

6. ³ª¸ÓÁö ¼³Á¤ : 
- ¾Æ·¡ Âü°íÀڷḦ ÂüÁ¶ÇÏÀÚ.
Âü°íÀÚ·á : https://commons.apache.org/proper/commons-dbcp/configuration.html



https://commons.apache.org/proper/commons-dbcp/configuration.html



BasicDataSource Configuration Parameters


Parameter Description
username The connection username to be passed to our JDBC driver to establish a connection.
password The connection password to be passed to our JDBC driver to establish a connection.
url The connection URL to be passed to our JDBC driver to establish a connection.
driverClassName The fully qualified Java class name of the JDBC driver to be used.
connectionProperties The connection properties that will be sent to our JDBC driver when establishing new connections.
Format of the string must be [propertyName=property;]*
NOTE - The "user" and "password" properties will be passed explicitly, so they do not need to be included here.

Parameter Default Description
defaultAutoCommit driver default The default auto-commit state of connections created by this pool. If not set then the setAutoCommit method will not be called.
defaultReadOnly driver default The default read-only state of connections created by this pool. If not set then the setReadOnly method will not be called. (Some drivers don't support read only mode, ex: Informix)
defaultTransactionIsolation driver default The default TransactionIsolation state of connections created by this pool. One of the following: (see javadoc)
  • NONE
  • READ_COMMITTED
  • READ_UNCOMMITTED
  • REPEATABLE_READ
  • SERIALIZABLE
defaultCatalog The default catalog of connections created by this pool.
cacheState true If true, the pooled connection will cache the current readOnly and autoCommit settings when first read or written and on all subsequent writes. This removes the need for additional database queries for any further calls to the getter. If the underlying connection is accessed directly and the readOnly and/or autoCommit settings changed the cached values will not reflect the current state. In this case, caching should be disabled by setting this attribute to false.
defaultQueryTimeout null If non-null, the value of this Integer property determines the query timeout that will be used for Statements created from connections managed by the pool. null means that the driver default will be used.
enableAutocommitOnReturn true If true, connections being returned to the pool will be checked and configured with Connection.setAutoCommit(true) if the auto commit setting is false when the connection is returned.
rollbackOnReturn true True means a connection will be rolled back when returned to the pool if auto commit is not enabled and the connection is not read-only.

Parameter Default Description
initialSize 0 The initial number of connections that are created when the pool is started.
Since: 1.2
maxTotal 8 The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit.
maxIdle 8 The maximum number of connections that can remain idle in the pool, without extra ones being released, or negative for no limit.
minIdle 0 The minimum number of connections that can remain idle in the pool, without extra ones being created, or zero to create none.
maxWaitMillis indefinitely The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or -1 to wait indefinitely.

NOTE: If maxIdle is set too low on heavily loaded systems it is possible you will see connections being closed and almost immediately new connections being opened. This is a result of the active threads momentarily closing connections faster than they are opening them, causing the number of idle connections to rise above maxIdle. The best value for maxIdle for heavily loaded system will vary but the default is a good starting point.


Parameter Default Description
validationQuery The SQL query that will be used to validate connections from this pool before returning them to the caller. If specified, this query MUST be an SQL SELECT statement that returns at least one row. If not specified, connections will be validation by calling the isValid() method.
validationQueryTimeout no timeout The timeout in seconds before connection validation queries fail. If set to a positive value, this value is passed to the driver via the setQueryTimeout method of the Statement used to execute the validation query.
testOnCreate false The indication of whether objects will be validated after creation. If the object fails to validate, the borrow attempt that triggered the object creation will fail.
testOnBorrow true The indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another.
testOnReturn false The indication of whether objects will be validated before being returned to the pool.
testWhileIdle false The indication of whether objects will be validated by the idle object evictor (if any). If an object fails to validate, it will be dropped from the pool.
timeBetweenEvictionRunsMillis -1 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.
numTestsPerEvictionRun 3 The number of objects to examine during each run of the idle object evictor thread (if any).
minEvictableIdleTimeMillis 1000 * 60 * 30 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).
softMinEvictableIdleTimeMillis -1 The minimum amount of time a connection may sit idle in the pool before it is eligible for eviction by the idle connection evictor, with the extra condition that at least "minIdle" connections remain in the pool. When minEvictableIdleTimeMillis is set to a positive value, minEvictableIdleTimeMillis is examined first by the idle connection evictor - i.e. when idle connections are visited by the evictor, idle time is first compared against minEvictableIdleTimeMillis (without considering the number of idle connections in the pool) and then against softMinEvictableIdleTimeMillis, including the minIdle constraint.
maxConnLifetimeMillis -1 The maximum lifetime in milliseconds of a connection. After this time is exceeded the connection will fail the next activation, passivation or validation test. A value of zero or less means the connection has an infinite lifetime.
logExpiredConnections true Flag to log a message indicating that a connection is being closed by the pool due to maxConnLifetimeMillis exceeded. Set this property to false to suppress expired connection logging that is turned on by default.
connectionInitSqls null A Collection of SQL statements that will be used to initialize physical connections when they are first created. These statements are executed only once - when the configured connection factory creates the connection.
lifo true True means that borrowObject returns the most recently used ("last in") connection in the pool (if there are idle connections available). False means that the pool behaves as a FIFO queue - connections are taken from the idle instance pool in the order that they are returned to the pool.

Parameter Default Description
poolPreparedStatements false Enable prepared statement pooling for this pool.
maxOpenPreparedStatements unlimited The maximum number of open statements that can be allocated from the statement pool at the same time, or negative for no limit.

This component has also the ability to pool PreparedStatements. When enabled a statement pool will be created for each Connection and PreparedStatements created by one of the following methods will be pooled:

  • public PreparedStatement prepareStatement(String sql)
  • public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)

NOTE - Make sure your connection has some resources left for the other statements. Pooling PreparedStatements may keep their cursors open in the database, causing a connection to run out of cursors, especially if maxOpenPreparedStatements is left at the default (unlimited) and an application opens a large number of different PreparedStatements per connection. To avoid this problem, maxOpenPreparedStatements should be set to a value less than the maximum number of cursors that can be open on a Connection.


Parameter Default Description
accessToUnderlyingConnectionAllowed false Controls if the PoolGuard allows access to the underlying connection.

When allowed you can access the underlying connection using the following construct:


    Connection conn = ds.getConnection();
   
Connection dconn = ((DelegatingConnection) conn).getInnermostDelegate();
   
...
    conn
.close()

Default is false, it is a potential dangerous operation and misbehaving programs can do harmful things. (closing the underlying or continue using it when the guarded connection is already closed) Be careful and only use when you need direct access to driver specific extensions.

NOTE: Do not close the underlying connection, only the original one.


Parameter Default Description
removeAbandonedOnMaintenance
removeAbandonedOnBorrow
false Flags to remove abandoned connections if they exceed the removeAbandonedTimout.
A connection is considered abandoned and eligible for removal if it has not been used for longer than removeAbandonedTimeout.
Creating a Statement, PreparedStatement or CallableStatement or using one of these to execute a query (using one of the execute methods) resets the lastUsed property of the parent connection.
Setting one or both of these to true can recover db connections from poorly written applications which fail to close connections.
Setting removeAbandonedOnMaintenance to true removes abandoned connections on the maintenance cycle (when eviction ends). This property has no effect unless maintenance is enabled by setting timeBetweenEvicionRunsMillis to a positive value.
If removeAbandonedOnBorrow is true, abandoned connections are removed each time a connection is borrowed from the pool, with the additional requirements that
  • getNumActive() > getMaxTotal() - 3; and
  • getNumIdle() < 2
removeAbandonedTimeout 300 Timeout in seconds before an abandoned connection can be removed.
logAbandoned false Flag to log stack traces for application code which abandoned a Statement or Connection.
Logging of abandoned Statements and Connections adds overhead for every Connection open or new Statement because a stack trace has to be generated.
abandonedUsageTracking false If true, the connection pool records a stack trace every time a method is called on a pooled connection and retains the most recent stack trace to aid debugging of abandoned connections. There is significant overhead added by setting this to true.

If you have enabled removeAbandonedOnMaintenance or removeAbandonedOnBorrow then it is possible that a connection is reclaimed by the pool because it is considered to be abandoned. This mechanism is triggered when (getNumIdle() < 2) and (getNumActive() > getMaxTotal() - 3) and removeAbandonedOnBorrow is true; or after eviction finishes and removeAbandonedOnMaintenance is true. For example, maxTotal=20 and 18 active connections and 1 idle connection would trigger removeAbandonedOnBorrow, but only the active connections that aren't used for more then "removeAbandonedTimeout" seconds are removed (default 300 sec). Traversing a resultset doesn't count as being used. Creating a Statement, PreparedStatement or CallableStatement or using one of these to execute a query (using one of the execute methods) resets the lastUsed property of the parent connection.


Parameter Default Description
fastFailValidation false When this property is true, validation fails fast for connections that have thrown "fatal" SQLExceptions. Requests to validate disconnected connections fail immediately, with no call to the driver's isValid method or attempt to execute a validation query.
The SQL_STATE codes considered to signal fatal errors are by default the following:
  • 57P01 (ADMIN SHUTDOWN)
  • 57P02 (CRASH SHUTDOWN)
  • 57P03 (CANNOT CONNECT NOW)
  • 01002 (SQL92 disconnect error)
  • JZ0C0 (Sybase disconnect error)
  • JZ0C1 (Sybase disconnect error)
  • Any SQL_STATE code that starts with "08"
To override this default set of disconnection codes, set the disconnectionSqlCodes property.
disconnectionSqlCodes null Comma-delimited list of SQL_STATE codes considered to signal fatal disconnection errors. Setting this property has no effect unless fastFailValidation is set to true.