VIRGIN FOREST OF JAVA
          不要埋頭苦干,要學習,學習,再學習。。。。。
          powered by R.Zeus

          ?public void closeConnection(Connection conn) throws SQLException {

          ??if ( log.isDebugEnabled() ) checkedOut--;

          //synchronized?pool to avoid concurrence error.??
          synchronized (pool) {
          ???int currentSize = pool.size();
          ???if ( currentSize < poolSize ) {
          ????if ( log.isTraceEnabled() ) log.trace("returning connection to pool, pool size: " + (currentSize + 1) );

          //add to pool
          ??
          ????pool.add(conn);
          ????return;
          ???}
          ??}

          ??log.debug("closing JDBC connection");

          ??conn.close();

          ?}


          ?public Connection getConnection() throws SQLException {

          ??if ( log.isTraceEnabled() ) log.trace( "total checked-out connections: " + checkedOut );

          //synchronized?pool to avoid concurrence error ???
          ?synchronized (pool) {
          ???if ( !pool.isEmpty() ) {

          //if the pool is not empty,return connection from the pool??

          ????
          ????int last = pool.size() - 1;
          ????if ( log.isTraceEnabled() ) {
          ?????log.trace("using pooled JDBC connection, pool size: " + last);
          ?????checkedOut++;
          ????}
          ????Connection pooled = (Connection) pool.remove(last);
          ????if (isolation!=null) pooled.setTransactionIsolation( isolation.intValue() );
          ????if ( pooled.getAutoCommit()!=autocommit ) pooled.setAutoCommit(autocommit);
          ????return pooled;
          ???}
          ??}

          ??log.debug("opening new JDBC connection");
          //create new connection.
          ??Connection conn = DriverManager.getConnection(url, connectionProps);
          ??if (isolation!=null) conn.setTransactionIsolation( isolation.intValue() );
          ??if ( conn.getAutoCommit()!=autocommit ) conn.setAutoCommit(autocommit);

          ??if ( log.isDebugEnabled() ) {
          ???log.debug( "created connection to: " + url + ", Isolation Level: " + conn.getTransactionIsolation() );
          ??}
          ??if ( log.isTraceEnabled() ) checkedOut++;

          ??return conn;
          ?}


          so you can see that when the connection will close,it actually not close and add to the pool if the pool size is not full.

          in other way , we can?firstly create a number of connection in the pool and when the pool is used out then create new connection to the call.

          I will see the C3P0ConnectionProvider next.

          A connection provider that uses java.sql.DriverManager. This provider
          ?also implements a very rudimentary connection pool.

          Note that you have to copy the required library into your classpath and use different connection pooling settings if you want to use a production-quality third party JDBC pooling software.


          posted on 2006-11-08 12:23 R.Zeus 閱讀(678) 評論(0)  編輯  收藏 所屬分類: Hibernate
          主站蜘蛛池模板: 松溪县| 兴隆县| 五大连池市| 伽师县| 延庆县| 拜泉县| 莱西市| 伊吾县| 麻阳| 临朐县| 临湘市| 昭平县| 金堂县| 丹凤县| 乐至县| 云安县| 利川市| 潜江市| 凌海市| 留坝县| 桐柏县| 昔阳县| 藁城市| 东安县| 阿城市| 通渭县| 天等县| 土默特右旗| 深泽县| 榕江县| 涡阳县| 府谷县| 溧阳市| 乐至县| 伽师县| 策勒县| 宁晋县| 通榆县| 浠水县| 梁平县| 湄潭县|