ÃֽŠ°Ô½Ã±Û(OS/WAS)
2023.12.18 / 13:46

Tomcat JDBC ¼³Á¤¿É¼Ç - jdbc ¼³Á¤ ¿É

XMaLL°ü¸®ÀÚ
Ãßõ ¼ö 34

Á¦°¡ ¿äÁò Tomcat À» ÀÚÁÖ Á¢ÇÏ°Ô µÇ³×¿ä..


ƯÈ÷


Could not close JDBC Connection java.sql.SQLException: Already closed.   ¶ó°í ¶ß¸é ȯÀåÇÕ´Ï´Ù.


±×·¡¼­ ¾Æ·¡ Æ÷½ºÆà ±ÛÀÌ µµ¿òÀÌ µÇ¾î ¿Ã·Áº¾´Ï´Ù.  °øºÎ¿¡ µµ¿òÀÌ µÇ½Ã±æ




Tomcat ¿¡¼­ JDBC ¿¬°á½Ã ÁÖÀÇ ÇؾßÇÒ »çÇ׿¡ ´ëÇؼ­ Á¤¸®Çغ¸°Ú½À´Ï´Ù.

 

1.     numTestsPerEvictionRun °ú initialSize µ¿ÀÏÇÏ°Ô ¼öÄ¡ ¸ÂÃß±â

initialSize="10", 

numTestsPerEvictionRun="10"

minIdle="10"

(Çؼ³)  initialSize¿Í numTestsPerEvictionRun °ªÀº µ¿ÀÏÇÏ°Ô ¼³Á¤µÇ´Â °ÍÀÌ ÁÁ½À´Ï´Ù.

(numTestsPerEvictionRun) »ç¿ëµÇÁö ¾Ê´Â Ä¿³Ø¼ÇÀ» °ËÁõÇÒ Ä¿³Ø¼Ç¼ö¿Í  ÃÖÃÊ ÃʱâÈ­ Ä¿³Ø¼Ç ¼ö°¡ µ¿ÀÏÇؾ߸¸ À̽´°¡ ¾È»ý±é´Ï´Ù.

 

username="xxx"

password="xxx" 

initialSize="10" 

maxActive="150" 

minIdle="10" 

maxIdle="70" 

maxWait="10"

testWhileIdle="false"

numTestsPerEvictionRun="10"   

 

2.     validationInterval ÀÇ ¼³Á¤ °ª Ãß°¡ (Tomcat 7.x °æ¿ì Àû¿ëÇϼ¼¿ä)

±âº»ÀûÀ¸·Î Tomcat 7 versionÀº validationInterval="30000" (default 30ÃÊ)°¡ ¼³Á¤µÇ¸ç, ¿ì¼±¼øÀ§·Î´Â 1¼øÀ§ ÀÔ´Ï´Ù.

À§ ¿É¼Ç ¼³Á¤½Ã ¾Æ·¡ µÎ°¡Áö ¼³Á¤ ½Ã°£µµ À¯ÀÇÇØÁÖ¼¼¿ä.

timeBetweenEvictionRunsMillis="600000"  // 10ºÐ, (±âº»°ª 5ÃÊ)

minEvictableIdleTimeMillis="1500000"   // 25ºÐ, (±âº»°ª 60ÃÊ)

 


timeBetweenEvictionRunsMillis="600000"    

minEvictableIdleTimeMillis="1500000"      

validationQuery="SELECT 1 FROM DUAL"

validationInterval="30000" 

testOnBorrow="true"

poolPreparedStatements="true"

maxOpenPreparedStatements="100"

removeAbandoned="true" 

removeAbandonedTimeout="60" 

logAbandoned="true" 

 

  validationQuery ¸Þ´º¾ó³»¿ë

(String) The SQL query that will be used to validate connections from this pool before returning them to the caller. If specified, this query does not have to return any data, it just can't throw aSQLException. The default value is null. Example values are SELECT 1(mysql), select 1 from dual(oracle), SELECT 1(MS Sql Server) 

 

 

3.     ±âŸ DB Pool ¿É¼Ç¼³¸í

 

  • poolPreparedStatements : ¿©·¯°³ÀÇ Äõ¸®¸¦ ¹­¾î ÇϳªÀÇ Æ®·£Àè¼ÇÀ¸·Î ó¸® ÇÑ´Ù. 
                                            (µ¿ÀÏÇÑ Äõ¸®¸¦ ij½¬Çؼ­ ¼º´ÉÇâ»óÀÌ µÊ)

     (boolean) Property not used.



  • testWhileIdle : true À̸é idle connectionµé¿¡ ´ëÇØ validation Å×½ºÆ®¼öÇà (default : false)

     (boolean) 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. NOTE - for a true value to have any effect, the validationQuery parameter must be set to a non-null string. The default value is false and this property has to be set in order for the pool cleaner/test thread is to run (also seetimeBetweenEvictionRunsMillis)



  • maxOpenPreparedStatements : poolingµÇ´Â statementsÀÇ ÃÖ´ë °ª. (º¸Åë 20°³Á¤µµ »ç¿ë)

     (int) Property not used.



  • testOnReturn : Connection Pool ¿¡ Connection À» ¹Ý³³ÇÒ ¶§ À¯È¿ÇÑ Connection ÀÎÁö °Ë»ç (default : false)

     (boolean) The indication of whether objects will be validated before being returned to the pool. NOTE - for a true value to have any effect, the validationQuery parameter must be set to a non-null string. The default value is false.



  • testOnBorrow : Connection Pool ·ÎºÎÅÍ Connection À» °¡Á®¿Ã ¶§ À¯È¿ÇÑ Connection ÀÎÁö °Ë»ç (default : false)

     (boolean) 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. NOTE - for a true value to have any effect, thevalidationQuery parameter must be set to a non-null string. In order to have a more efficient validation, see validationInterval. Default value is false

    [Ãâó] Apache commons-dbcp °£´Ü ºÐ¼®|ÀÛ¼ºÀÚ

## ÁÖÀÇ : validationQuery ¼³Á¤¾ÈµÇÀÖÀ¸¸é À§ ¼³Á¤°ªÀº Àǹ̰¡ ¾ø½À´Ï´Ù.

±×·¸ ¿­°øÇϼ¼¿ä~!!