<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    溫馨提示:您的每一次轉載,體現了我寫此文的意義!!!煩請您在轉載時注明出處http://www.tkk7.com/sxyx2008/謝謝合作!!!

    雪山飛鵠

    溫馨提示:您的每一次轉載,體現了我寫此文的意義!!!煩請您在轉載時注明出處http://www.tkk7.com/sxyx2008/謝謝合作!!!

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks

    BoneCP is a fast, free, open-source, Java database connection pool (JDBC Pool) library. If you are familiar with C3P0 and DBCP then you already know what this means. For the rest, this is a library that will manage a database connection for you to get faster database access in your application.
    BoneCP is fast! For some tests, it's almost 25 times faster than the next fastest connection pool option, not to mention that BoneCP never spin-locks so it won't slow down your application.
    官方主頁:http://jolbox.com/
    下載地址:http://jolbox.com/bonecp/downloads/maven/com/jolbox/bonecp/
    目前最新版本為:0.6.7.2
    依賴的jar包:

  • A database that accepts connections
  • A driver to go with it
  • Google Guava library, available for free from here.
  • The SLF4J logging library.
  • JDK1.5 or higher.


    bonecp-0.7.0.jar
    google-collections-1.0.jar
    log4j-1.2.15.jar
    mysql-connector-java-5.1.6-bin.jar(mysql驅動)
    slf4j-api-1.5.10.jar
    slf4j-log4j12-1.5.10.jar
    以上jar包可以在這里下載http://jolbox.com/bonecp/downloads/maven/

    官方性能測試:

    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

    Multi-Thread 10ms delay

    • 500 threads each attempting 100 get/release connection
    • We introduce a 10ms delay (Thread.sleep()) between the acquire connection and the release connection to simulate work being done with the connection.
    • Pool size range: 50-200.
    • Acquire increment: 5
    • Helper threads: 5

    Multi-Thread 25ms delay

    • 500 threads each attempting 100 get/release connection
    • We introduce a 25ms delay (Thread.sleep()) between the acquire connection and the release connection to simulate work being done with the connection.
    • Pool size range: 50-200.
    • Acquire increment: 5
    • Helper threads: 5

    Multi-Thread 50ms delay

    • 500 threads each attempting 100 get/release connection
    • We introduce a 50ms delay (Thread.sleep()) between the acquire connection and the release connection to simulate work being done with the connection.
    • Pool size range: 50-200.
    • Acquire increment: 5
    • Helper threads: 5

    Multi-Thread 75ms delay

    • 500 threads each attempting 100 get/release connection
    • We introduce a 75ms delay (Thread.sleep()) between the acquire connection and the release connection to simulate work being done with the connection.
    • Pool size range: 50-200.
    • Acquire increment: 5
    • Helper threads: 5

    Prepared Statement (single threaded)

    • Fetches a single connection then calls 1,000,000 connection.prepareStatement(...) followed by an immediate statement close.
    • No delay between calls
    • Max statements: 30
    • Max statements per connection: 30
    • Helper threads: 5

    Prepared Statement (multi-threaded)

    • 500 Threads each attempting 100 get/release connection with no delays. After obtaining a connection, make a call to connection.prepareStatement(...) followed by a close statement request.
    • No delay between calls
    • Pool size range: 50-200.
    • Acquire increment: 5.
    • Helper threads: 5

    Prepared Statement (multi-threaded, 10ms delay)

    • 500 Threads each attempting 100 get/release connection with no delays. After obtaining a connection, make a call to connection.prepareStatement(...) followed by a close statement request.
    • 10ms delay between open connection/release connection to simulate work done by the application.
    • Pool size range: 50-200.
    • Acquire increment: 5.
    • Helper threads: 5

    Prepared Statement (multi-threaded, 25ms delay)

    • 500 Threads each attempting 100 get/release connection with no delays. After obtaining a connection, make a call to connection.prepareStatement(...) followed by a close statement request.
    • 25ms delay between open connection/release connection to simulate work done by the application.
    • Pool size range: 50-200.
    • Acquire increment: 5.
    • Helper threads: 5

    Prepared Statement (multi-threaded, 50ms delay)

    • 500 Threads each attempting 100 get/release connection with no delays. After obtaining a connection, make a call to connection.prepareStatement(...) followed by a close statement request.
    • 50ms delay between open connection/release connection to simulate work done by the application.
    • Pool size range: 50-200.
    • Acquire increment: 5.
    • Helper threads: 5

    Prepared Statement (multi-threaded, 75ms delay)

    • 500 Threads each attempting 100 get/release connection with no delays. After obtaining a connection, make a call to connection.prepareStatement(...) followed by a close statement request.
    • 75ms delay between open connection/release connection to simulate work done by the application.
    • Pool size range: 50-200.
    • Acquire increment: 5.
    • Helper threads: 5

    點我下載本文工程代碼
    在jdbc中使用BoneCP連接池


  • package com.bonecp;
     
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
     
    import com.jolbox.bonecp.BoneCP;
    import com.jolbox.bonecp.BoneCPConfig;
     
    /** 
     * 
    @author sxyx2008
     *
     
    */
    public class ExampleJDBC {
     
        
    public static void main(String[] args) {
            BoneCP connectionPool 
    = null;
            Connection connection 
    = null;
     
            
    try {
                
    // load the database driver (make sure this is in your classpath!)
                Class.forName("com.mysql.jdbc.Driver");
            } 
    catch (Exception e) {
                e.printStackTrace();
                
    return;
            }
            
            
    try {
                
    // setup the connection pool
                BoneCPConfig config = new BoneCPConfig();
                config.setJdbcUrl(
    "jdbc:mysql://localhost:3306/demo"); // jdbc url specific to your database, eg jdbc:mysql://127.0.0.1/yourdb
                config.setUsername("root"); 
                config.setPassword(
    "root");
                
    //設置每60秒檢查數據庫中的空閑連接數
                config.setIdleConnectionTestPeriod(60);
                
    //設置連接空閑時間
                config.setIdleMaxAge(240);
                
    //設置每個分區中的最大連接數 30
                config.setMaxConnectionsPerPartition(30);
                
    //設置每個分區中的最小連接數 10
                config.setMinConnectionsPerPartition(10);
                
    //當連接池中的連接耗盡的時候 BoneCP一次同時獲取的連接數
                config.setAcquireIncrement(5);
                
    //連接釋放處理
                config.setReleaseHelperThreads(3);
                
    //設置分區  分區數為3
                config.setPartitionCount(3);
                
    //設置配置參數
                connectionPool = new BoneCP(config); // setup the connection pool
                
                connection 
    = connectionPool.getConnection(); // fetch a connection
                
                
    if (connection != null){
                    System.out.println(
    "Connection successful!");
                    Statement stmt 
    = connection.createStatement();
                    ResultSet rs 
    = stmt.executeQuery(" select * from person "); // do something with the connection.
                    while(rs.next()){
                        System.out.println(rs.getString(
    1)); // should print out "1"'
                        System.out.println(rs.getString(2)); // should print out "1"'
                    }
                }
                connectionPool.shutdown(); 
    // shutdown connection pool.
            } catch (SQLException e) {
                e.printStackTrace();
            } 
    finally {
                
    if (connection != null) {
                    
    try {
                        connection.close();
                    } 
    catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }


    使用DataSource

    package com.bonecp;

    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;

    import com.jolbox.bonecp.BoneCPDataSource;

    public class ExampleDataSource {
        
        
    public static void main(String[] args) {
            
            Connection connection 
    = null;
            
            
    try {
                Class.forName(
    "com.mysql.jdbc.Driver");
            } 
    catch (Exception e) {
                e.printStackTrace();
            }
            
            BoneCPDataSource dataSource
    =new BoneCPDataSource();
            dataSource.setUsername(
    "root");
            dataSource.setPassword(
    "root");
            dataSource.setJdbcUrl(
    "jdbc:mysql://localhost:3306/demo");
            dataSource.setMaxConnectionsPerPartition(
    10);
            dataSource.setMinConnectionsPerPartition(
    5);
            dataSource.setIdleConnectionTestPeriod(
    60);
            dataSource.setIdleMaxAge(
    240);
            dataSource.setAcquireIncrement(
    5);
            dataSource.setReleaseHelperThreads(
    3);
            
    try {
                connection
    =dataSource.getConnection();
                
    if (connection != null){
                    System.out.println(
    "Connection successful!");
                    Statement stmt 
    = connection.createStatement();
                    ResultSet rs 
    = stmt.executeQuery(" select * from person "); // do something with the connection.
                    while(rs.next()){
                        System.out.println(rs.getString(
    1)); // should print out "1"'
                        System.out.println(rs.getString(2)); // should print out "1"'
                    }
                }
            } 
    catch (SQLException e) {
                e.printStackTrace();
            }
    finally{
                
    try {
                    connection.close();
                } 
    catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            
            
        }
        
    }


    在Hibernate中使用BoneCP
    在Hibernate中使用BoneCP除了需要上面提到的jar包之外,還需要下載一個名為bonecp-provider-0.7.0.jar的bonecp-provider的jar包,它的下載位置是:http://jolbox.com/bonecp/downloads/maven/com/jolbox/bonecp-provider/0.7.0/bonecp-provider-0.7.0.jar。
    除此之外,還需要做如下配置:

    1. <!-- Hibernate SessionFactory -->  
    2. <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean" autowire="autodetect">  
    3.     <property name="hibernateProperties">  
    4.         <props>  
    5.             <prop key="hibernate.connection.provider_class">com.jolbox.bonecp.provider.BoneCPConnectionProvider</prop>  
    6.             <prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>  
    7.             <prop key="hibernate.connection.url">jdbc:mysql://127.0.0.1/yourdb</prop>  
    8.             <prop key="hibernate.connection.username">root</prop>  
    9.             <prop key="hibernate.connection.password">abcdefgh</prop>  
    10.             <prop key="bonecp.idleMaxAge">240</prop>  
    11.             <prop key="bonecp.idleConnectionTestPeriod">60</prop>  
    12.             <prop key="bonecp.partitionCount">3</prop>  
    13.             <prop key="bonecp.acquireIncrement">10</prop>  
    14.             <prop key="bonecp.maxConnectionsPerPartition">60</prop>  
    15.             <prop key="bonecp.minConnectionsPerPartition">20</prop>  
    16.             <prop key="bonecp.statementsCacheSize">50</prop>  
    17.             <prop key="bonecp.releaseHelperThreads">3</prop>  
    18.         </props>  
    19.     </property>  
    20. </bean>  

    xml方式配置bonecp

    <?xml version="1.0" encoding="UTF-8"?>
    <bonecp-config>  
      
    <default-config>  
        
    <property name="jdbcUrl">jdbc:oracle:thin:@127.0.0.1:1521:orcl</property>  
        
    <property name="username">scott</property>  
        
    <property name="password">tiger</property>  
        
    <property name="partitionCount">3</property>  
        
    <property name="maxConnectionsPerPartition">30</property>  
        
    <property name="minConnectionsPerPartition">10</property>  
        
    <property name="acquireIncrement">3</property>  
      
    </default-config>   
    </bonecp-config> 
    連接代碼

    package com.bonecp;
     
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;

    import com.jolbox.bonecp.BoneCP;
    import com.jolbox.bonecp.BoneCPConfig;
     
    /** 
     * 
    @author sxyx2008
     *
     
    */
    public class ExampleJDBC {
     
        
    public static void main(String[] args) {
            BoneCP connectionPool 
    = null;
            
            Connection connection 
    = null;
            
    try {
                
    // load the database driver (make sure this is in your classpath!)
                Class.forName("oracle.jdbc.driver.OracleDriver");
            } 
    catch (Exception e) {
                e.printStackTrace();
                
    return;
            }
            
            
    try {
                
    // setup the connection pool
                BoneCPConfig config = null;
                
    try {
                    config 
    = new BoneCPConfig("bonecp-config.xml");
                } 
    catch (Exception e) {
                    e.printStackTrace();
                }
                
    /*
                config.setJdbcUrl("jdbc:oracle:thin:@127.0.0.1:1521:orcl"); // jdbc url specific to your database, eg jdbc:mysql://127.0.0.1/yourdb
                config.setUsername("scott"); 
                config.setPassword("tiger");
                //設置每60秒檢查數據庫中的空閑連接數
                config.setIdleConnectionTestPeriod(60);
                //設置連接空閑時間
                config.setIdleMaxAge(240);
                //設置每個分區中的最大連接數 30
                config.setMaxConnectionsPerPartition(30);
                //設置每個分區中的最小連接數 10
                config.setMinConnectionsPerPartition(10);
                //當連接池中的連接耗盡的時候 BoneCP一次同時獲取的連接數
                config.setAcquireIncrement(5);
                //連接釋放處理
                config.setReleaseHelperThreads(3);
                //設置分區  分區數為3
                config.setPartitionCount(3);
                
    */
                
    //設置配置參數
                connectionPool = new BoneCP(config); // setup the connection pool
                
                
    long startTime=System.currentTimeMillis();
                
    //創建100個連接
                for (int i = 0; i < 100; i++) {
                    connection 
    = connectionPool.getConnection(); // fetch a connection
                }
                
    long endtTime=System.currentTimeMillis();
                
                System.out.println(
    "-------->total seconds :"+(endtTime-startTime));
                
                
    if (connection != null){
                    System.out.println(
    "Connection successful!");
                    Statement stmt 
    = connection.createStatement();
                    ResultSet rs 
    = stmt.executeQuery(" select * from emp "); // do something with the connection.
                    while(rs.next()){
                        System.out.println(rs.getString(
    1)); // should print out "1"'
                        System.out.println(rs.getString(2)); // should print out "1"'
                    }
                }
                connectionPool.shutdown(); 
    // shutdown connection pool.
            } catch (SQLException e) {
                e.printStackTrace();
            } 
    finally {
                
    if (connection != null) {
                    
    try {
                        connection.close();
                    } 
    catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
  • 點我下載本文工程代碼
    posted on 2011-03-16 14:48 雪山飛鵠 閱讀(8098) 評論(0)  編輯  收藏 所屬分類: database
    主站蜘蛛池模板: 13一14周岁毛片免费| 一级黄色片免费观看| 免费看黄视频网站| 亚洲经典在线观看| 51精品视频免费国产专区| 亚洲精品电影在线| 人与禽交免费网站视频| 亚洲伦理一二三四| 国产成在线观看免费视频| 久久乐国产综合亚洲精品| 免费黄色小视频网站| 亚洲人成网亚洲欧洲无码| 日本免费v片一二三区| 免费国产污网站在线观看不要卡| 亚洲一级片在线观看| 麻豆国产精品免费视频| 亚洲AV综合色区无码二区爱AV| 毛片a级三毛片免费播放| 亚洲AⅤ男人的天堂在线观看| 四虎永久精品免费观看| caoporn成人免费公开| 国产AV无码专区亚洲A∨毛片| 国产真人无码作爱视频免费| 97亚洲熟妇自偷自拍另类图片| 免费观看激色视频网站(性色)| 中文字幕乱码亚洲精品一区| 国产免费观看a大片的网站| 国产成人精品免费视频大全| 久久久久久亚洲av成人无码国产| 亚洲视频免费一区| 爱情岛论坛亚洲品质自拍视频网站| 亚洲日本韩国在线| 亚洲精品在线免费看| 亚洲欧美黑人猛交群| 中文亚洲AV片在线观看不卡| 免费在线观看h片| 边摸边吃奶边做爽免费视频99| 欧洲亚洲国产清在高| 成人超污免费网站在线看| 亚洲天堂免费在线视频| 亚洲人成777在线播放|