`
chenzehe
  • 浏览: 532360 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

BoneCP源码——概述

 
阅读更多

BoneCP是一个开源的Java数据库连接池,其内部使用了JDK1.5的并发包java.util.concurrent来保证同步,而且采用分段思想,避免单点加锁的竞争(ConcurrentHashMap也是使用这种思想来实现的),具有以下特点(官网):   

  • Highly scalable, fast connection pool
  • Callback (hook interceptor) mechanisms on a change of connection state.
  • Partitioning capability to increase performance
  • Allows direct access to a connection/statements
  • Automatic resizing of pool
  • Statement caching support
  • Support for obtaining a connection asynchronously (by returning a Future<Connection>)
  • Release helper threads to release a connection/statement in an asynchronous fashion for higher performance.
  • Easy mechanism to execute a custom statement on each newly obtained connection (initSQL).
  • Support to switch to a new database at runtime without shutting down an application
  • Ability to replay any failed transaction automatically (for the case where database/network goes down etc)
  • JMX support
  • Lazy initialization capable
  • Support for XML/property configuration
  • Idle connection timeouts / max connection age support
  • Automatic validation of connections (keep-alives etc)
  • Allow obtaining of new connections via a datasource rather than via a Driver
  • Datasource/Hibernate support capable
  • Debugging hooks to highlight the exact place where a connection was obtained but not closed
  • Debugging support to show stack locations of connections that were closed twice.
  • Custom pool name support.
  • Clean organised code. 100% unit test branch code coverage (over 180 JUnit tests).
  • Free, open source and written in 100% pure Java with complete Javadocs.

 官网上提供的跟其它连接池的性能测试对比:

Single Thread

  • 1,000,000 get connection / release connection requests
  • No delay between getting/releasing connection.
  • Pool size range: 20-50.
  • Acquire increment: 5
  • Helper threads: 1
  • Partition count: 1

Multi-Thread

  • 500 threads each attempting 100 get/release connection
  • No delay between getting/releasing connection.
  • Pool size range: 50-200.
  • Acquire increment: 5
  • Helper threads: 5

 

 本次学习基于bonecp-0.7.1.RELEASE版本,主要jar包如下:

com.jolbox.bonecp                  连接池核心包
com.jolbox.bonecp.hooks       支持connection状态改变时的事件通知
com.jolbox.bonecp.proxy        代理java.sql.*下的接口,仅供内部使用
此版本主要依赖的外部包有:

slf4j
guava(google lib)

jsr166y

提供外部支持和测试
com.jolbox.bonecp.provider
com.jolbox.bonecp.spring

 

 

分享到:
评论
1 楼 Arbow 2013-06-27  
请教一个问题。现在互联网业务的数据库通常用分片方式来连接一组数据库,比如对于同一个物理库,会有

jdbc:mysql://xxx.xxx:3466/user1
jdbc:mysql://xxx.xxx:3466/user2
jdbc:mysql://xxx.xxx:3466/user3
...
jdbc:mysql://xxx.xxx:3466/user10

这样大量的jdbc链接,如果一个库配置至少5个连接,并且有多个jvm服务在运行,这样对于一个物理库连接上的并发链接是比较多的。能否通过对物理库做一个大的连接池,操作具体的逻辑库时再通过执行类似using xxx;这样的方式来减少连接数?

相关推荐

Global site tag (gtag.js) - Google Analytics