Bonecp´Â dbcp, c3p0 ¸¦ ´ëüÇÏ´Â °í¼º´ÉÀÇ Java database connection pool ±¸Çö¹°.
»ç¿ëÁ¶°Ç
- JDK 1.5 ÀÌ»ó
- Google Guava library ÇÊ¿ä
- SLF4J logging library ÇÊ¿ä
¼³Á¤ °ª ¹× ¼º´É ÀÚ·á
¼³Á¤°ª
- partitionCount : Pool ¿¡¼ connection À» °¡Á®¿Ã¶§ lock °æÀïÀ» ÃÖ¼ÒÈÇϱâ À§ÇØ pool À» ¿©·¯ °³ ÆÄƼ¼ÇÀ¸·Î ³ª´¼ö ÀÖÀ½. ±âº»°ªÀº 1ÀÌ¸ç ³ôÀº ¼º´ÉÀÌ ÇÊ¿äÇÒ ¶§ 3~4 Á¤µµ Ãßõ
- maxConnectionsPerPartition: ÆÄƼ¼Çº° Connection ¼ö. Àüü Connection Àº partitionCount * maxConnectionsPerPartion ÀÌ µÊ.(3°³ ÆÄƼ¼ÇÀÌ ÀÖ°í maxConnectionsPerPartion ÀÌ 5¸é Àüü DB Connection Àº 15°¡ µÊ)
- acquireIncrement: ÆÄƼ¼Ç³» Connection ÀÌ ¸ðµÎ ¼Ò¸ðµÇ¾úÀ»¶§ ´Ã¸± Connection Count. ±âº»°ªÀº 10 À̸ç Àüü Count°¡ ¾Æ´Ï¶ó ÆÄƼ¼Çº° countÀÓ
¼º´É ºñ±³
WASÀÇ JNDI ·Î »ç¿ë
TOMCAT ¼³Á¤
https://github.com/wwadge/bonecp/blob/master/bonecp/src/main/resources/bonecp-default-config.xml
< Resource name = "jdbc/spring-demo" auth = "Container"
driverClass = "com.mysql.jdbc.Driver"
username = "springdemo"
password = "demo1234"
idleConnectionTestPeriodInMinutes = "60"
idleMaxAgeInMinutes = "60"
maxConnectionsPerPartition = "30"
minConnectionsPerPartition = "5"
partitionCount = "3"
acquireIncrement = "5"
statementsCacheSize = "100"
factory = "org.apache.naming.factory.BeanFactory"
type = "com.jolbox.bonecp.BoneCPDataSource"
jdbcUrl = "jdbc:mysql://localhost:3306/springdemo?autoReconnect=true&useUnicode=true&characterEncoding=utf8"
/>
|
SpringÀÇ AppContext
<?xml version= "1.0" encoding= "UTF-8" ?>
xsi:schemaLocation="http:
http:
http:
http:
http:
http:
<jee:jndi-lookup id= "jdbc/spring-demo" jndi-name= "jdbc/spring-demo" expected-type= "javax.sql.DataSource" />
<bean id= "sqlSessionFactory" class = "org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref= "jdbc/spring-demo"
p:mapperLocations= "classpath:/mycom/mypkg/mapper/*mapper.xml"
p:configLocation= "classpath:/mycom/mypkg/mybatis-config.xml"
/>
<bean class = "org.mybatis.spring.mapper.MapperScannerConfigurer"
p:basePackage= "mycom.mypkg.mapper" />
<bean id= "transactionManager" class = "org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref= "jdbc/spring-demo" />
</beans>
|
Spring ÀÇ appContext¿¡¼ »ç¿ë
Application Context ¿¡ ´ÙÀ½ ³»¿ë Ãß°¡
<? xml version = "1.0" encoding = "UTF-8" ?>
< bean id = "mainDataSource" class = "com.jolbox.bonecp.BoneCPDataSource" destroy-method = "close" >
< property name = "driverClass" value = "com.mysql.jdbc.Driver" />
< property name = "jdbcUrl" value = "jdbc:mysql://localhost:3306/springdemo?autoReconnect=true&useUnicode=true&characterEncoding=utf8" />
< property name = "username" value = "springdemo" />
< property name = "password" value = "demo1234" />
< property name = "idleConnectionTestPeriod" value = "60" />
< property name = "idleMaxAge" value = "240" />
< property name = "maxConnectionsPerPartition" value = "30" />
< property name = "minConnectionsPerPartition" value = "10" />
< property name = "partitionCount" value = "3" />
< property name = "acquireIncrement" value = "5" />
< property name = "statementsCacheSize" value = "100" />
< property name = "releaseHelperThreads" value = "3" />
</ bean >
< bean id = "sqlSessionFactory" class = "org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref = "mainDataSource" p:mapperLocations = "classpath:/mycompany/mypkg/mapper/*mapper.xml"
p:configLocation = "classpath:/mycompany/mypkg/mybatis-config.xml" />
< bean class = "org.mybatis.spring.mapper.MapperScannerConfigurer"
p:basePackage = "mycompany.mypkg.mapper" />
< bean id = "transactionManager"
class = "org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref = "mainDataSource" />
</ beans >
|
maven pom.xml ¿¡ Ãß°¡
< dependencies >
< dependency >
< groupId >com.jolbox</ groupId >
< artifactId >bonecp</ artifactId >
< version >0.8.0.RELEASE</ version >
</ dependency >
</ dependencies >
< repositories >
< repository >
< releases >
< enabled >true</ enabled >
</ releases >
< id >bonecp-repo</ id >
< name >BoneCP Repository</ name >
</ repository >
</ repositories >
|
log4j ¼³Á¤
log4j.category.com.jolbox=DEBUG,Console
|
See Also
Ref