锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国模吧精品人体gogo,欧美在线一区二区三区,在线播放免费avhttp://www.aygfsteel.com/chars/鍦ㄥ璞$殑澶╁湴蹇箰鐨勬垚闀?......zh-cnWed, 18 Jun 2025 11:34:30 GMTWed, 18 Jun 2025 11:34:30 GMT60榪炴帴姹犵殑涓縐嶅疄鐜版柟寮?/title><link>http://www.aygfsteel.com/chars/archive/2007/07/02/127644.html</link><dc:creator>chars</dc:creator><author>chars</author><pubDate>Mon, 02 Jul 2007 09:46:00 GMT</pubDate><guid>http://www.aygfsteel.com/chars/archive/2007/07/02/127644.html</guid><wfw:comment>http://www.aygfsteel.com/chars/comments/127644.html</wfw:comment><comments>http://www.aygfsteel.com/chars/archive/2007/07/02/127644.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/chars/comments/commentRss/127644.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/chars/services/trackbacks/127644.html</trackback:ping><description><![CDATA[<blockquote dir=ltr style="MARGIN-RIGHT: 0px"> <p>package chars.pool;<br>import java.sql.Connection;<br>import java.sql.DatabaseMetaData;<br>import java.sql.Driver;<br>import java.sql.DriverManager;<br>import java.sql.SQLException;<br>import java.util.ArrayList;<br>import java.util.List;<br>import java.util.Properties;</p> <p>import COM.ibm.db2.jdbc.app.DB2Driver;</p> <p>/**<br> * JDK version used : jdk1.4.2_07 <br><br> * Description : 涓涓暟鎹簱榪炴帴姹犵殑瀹炵幇 <br><br> * Comments Name : CharsConnectionPool <br><br> * author 錛歝hars <br><br> * date 錛?007-06-11<br><br> * Version : 1.00 <br><br> */<br>public class CharsConnectionPool<br>{<br>   //---------------榪炴帴鏁版嵁搴撴墍闇瑕佺殑鍏冪礌---------------<br> private String driver;</p> <p> private String url;</p> <p> private String userName;</p> <p> private String password;</p> <p>  //----------------------------------------------<br> private List connections = null;//榪炴帴姹犵殑瀹瑰櫒</p> <p> private  int intiateCount = 10;// 鍒濆鍖栬繛鎺ユ暟</p> <p> private  int maxCount = 100;// 榪炴帴姹犲彲浠ヤ駭鐢熺殑鏈澶ц繛鎺ユ暟</p> <p> private  int rateCount = 10;// 榪炴帴涓嶅鏃朵竴嬈″彲浠ョ敵璇風殑榪炴帴鏁?br> <br> public static int ACTIVE_ACOUNT = 0;//璁板綍鐩墠鐨勬椿鍔ㄨ繛鎺ユ暟</p> <p> public String getDriver()<br> {<br>     return driver;<br> }</p> <p> public void setDriver(String driver)<br> {<br>     this.driver = driver;<br> }</p> <p> public int getIntiateCount()<br> {<br>     return intiateCount;<br> }</p> <p> public void setIntiateCount(int intiateCount)<br> {<br>     this.intiateCount = intiateCount;<br> }</p> <p> public int getMaxCount()<br> {<br>     return maxCount;<br> }</p> <p> public void setMaxCount(int maxCount)<br> {<br>     this.maxCount = maxCount;<br> }</p> <p> public String getPassword()<br> {<br>     return password;<br> }</p> <p> public void setPassword(String password)<br> {<br>     this.password = password;<br> }</p> <p> public int getRateCount()<br> {<br>     return rateCount;<br> }</p> <p> public void setRateCount(int rateCount)<br> {<br>     this.rateCount = rateCount;<br> }</p> <p> public String getUrl()<br> {<br>     return url;<br> }</p> <p> public void setUrl(String url)<br> {<br>     this.url = url;<br> }</p> <p> public String getUserName()<br> {<br>     return userName;<br> }</p> <p> public void setUserName(String userName)<br> {<br>     this.userName = userName;<br> }<br>    /**<br>     * 榪炴帴姹犳瀯閫犲嚱鏁?br>     * @param driver<br>     * @param url<br>     * @param userName<br>     * @param password<br>     * @param connections<br>     */<br> public CharsConnectionPool(String driver, String url, String userName, String password)<br> {<br>    super();<br>    this.driver = driver;<br>    this.url = url;<br>    this.userName = userName;<br>    this.password = password;<br> }<br> <br> public CharsConnectionPool(Properties p)<br> {<br>    super();<br>    this.driver = p.getProperty("driver");<br>    this.url =  p.getProperty("url");<br>    this.userName = p.getProperty("userName");<br>    this.password = p.getProperty("password");<br> }</p> <p> /**<br>  * 鍒濆鍖栬繛鎺ユ睜<br>  * <br>  */<br> public void initiatePools()throws Exception<br> {<br>     if (connections != null)return;//濡傛灉榪炴帴姹犲凡緇忓緩绔嬪垯涓嶅啀嬈¤繘琛屽垵濮嬪寲<br>  <br>     connections = new ArrayList();<br>     initParamters();//鏍規嵁鏁版嵁搴撴敮鎸佺殑鏈澶ц繛鎺ユ暟閰嶇疆璇ヨ繛鎺ユ睜鐨勭浉鍏沖弬鏁?<br>     for (int i = 0; i < intiateCount; i++){<br>     connections.add(newCharsConnection());<br>  }<br> }<br> /**<br>  * 閿姣佽繛鎺ユ睜<br>  * @throws Exception<br>  */<br> public void destoryPools()throws Exception<br> {<br>     if (connections == null) return ;<br>     for(int i=0; i<connections.size();i++){<br>     CharsPoolConnection conn = (CharsPoolConnection)connections.get(i);<br>   <br>     if(conn.isBusy()) Thread.sleep(5000);//濡傛灉璇ヨ繛鎺ユ鍦ㄤ嬌鐢ㄥ垯鍐嶇粰5縐掓椂闂?br>     closeConnection(conn.getConnection());<br>     connections.remove(conn);<br>  }<br>  connections = null;<br> }<br>    /**<br>     * 浠庤繛鎺ユ睜鑾峰彇榪炴帴<br>     *<br>     */<br> public Connection getConnection()throws SQLException<br> {<br>        Connection conn = null;<br>        try{<br>         <br>         conn = getFreeConnection();        <br>         if(conn == null) {<br>           Thread.sleep(3000);//鏆傚仠3縐掗挓鍐嶈瘯鐫鑾峰彇榪炴帴<br>           conn = getFreeConnection();<br>         }       <br>         if(conn == null) {//姝ゆ椂濡傛灉榪樹笉鑳借幏寰楄繛鎺ュ垯琛ㄧず,榪炴帴姹犱腑鐨勮繛鎺ュ凡緇忕敤瀹?br>          throw new SQLException("榪炴帴姹犺繛鎺ヨ繛鎺ヤ嬌鐢ㄦ灟绔?璇風◢鍚庡啀璇?!");<br>         }<br>        }catch(Exception e)<br>        {<br>         e.printStackTrace();<br>        }<br>        return conn;<br> }<br>    /**<br>     * 褰掕繕榪炴帴鍒拌繛鎺ユ睜(褰撹繛鎺ョ敤瀹屾椂)<br>     * @param conn<br>     */<br> public void rebackConnection(Connection conn)<br> {<br>           for(int i = 0;i < connections.size();i++){<br>            CharsPoolConnection charsCon = (CharsPoolConnection)connections.get(i);<br>            if(charsCon.getConnection() == conn){<br>             charsCon.setBusy(false);<br>             conn = null;//澶栭儴寮曠敤涓虹┖.<br>             ACTIVE_ACOUNT --;<br>             break;<br>            }<br>           }<br> }<br>    <br> // ---------------------------------------------------------------------------------------------------<br>    /**<br>     * 鍔犺澆椹卞姩紼嬪簭,閰嶇疆瀹為檯涓婂彲浠ョ敤鐨勬渶澶ц繛鎺ユ暟<br>     */<br> private void initParamters() throws Exception<br> {<br>    int realMaxCount = -1;<br>   Connection con = null;<br>   try<br>  {<br>      Driver driver1 = new DB2Driver();<br>      DriverManager.registerDriver(driver1);   <br>      con = DriverManager.getConnection(this.url, this.userName, this.password);   <br>      DatabaseMetaData dmd = con.getMetaData();<br>      realMaxCount = dmd.getMaxConnections();<br>   <br>     if(realMaxCount == 0){//濡傛灉榪斿洖鐨勫間負0,鍒欒〃紺烘渶澶х殑榪炴帴鏁頒笉鍙楅檺鍒?br>      realMaxCount = 1000;//閭d箞榛樿璧嬩竴涓緝澶х殑鍊肩粰瀹?br>   }<br>  }<br>  finally{<br>     if(con == null) con.close();<br>  }<br>  <br>  if(realMaxCount < intiateCount) {//濡傛灉鏁版嵁搴撳厑璁哥殑鏈澶ф椿鍔ㄨ繛鎺ユ暟灝忎簬鍒濆鍖栫殑榪炴帴鏁?br>    intiateCount = maxCount;     //鍒欏疄闄呬笂鍒濆鍖栫殑榪炴帴鏁板簲璇ョ瓑浜庢暟鎹簱鍏佽鐨勬渶澶ф椿鍔ㄨ繛鎺ユ暟鎹?br>    maxCount = realMaxCount;<br>  }<br>  else if(intiateCount < realMaxCount && maxCount >= realMaxCount){//濡傛灉鏁版嵁搴撴渶澶х殑媧誨姩榪炴帴鏁板ぇ浜庡垵濮嬪寲榪炴帴鏁頒絾鏄皬浜庤榪炴帴姹犲厑璁哥殑鏈澶ц繛鎺ユ暟<br>    maxCount = realMaxCount;                                     //鍒欒姹犵殑鏈澶ц繛鎺ユ暟絳変簬鏁版嵁搴撳厑璁哥殑鏈澶ф椿鍔ㄨ繛鎺ユ暟<br>  }<br> }<br> /**<br>  * 鑾峰彇鍙互鐢ㄧ殑榪炴帴,濡傛灉娌℃湁鏌ユ壘鍒板垯鏍規嵁鏉′歡鍦ㄦ睜涓姞鍏ユ柊鐨勮繛鎺?br>  * @return<br>  * @throws SQLException<br>  */<br> private Connection getFreeConnection()throws SQLException<br> {<br>     Connection conn = null;<br>     conn = findFreeConnection();//棣栧厛鍒拌繛鎺ユ睜涓壘絀洪棽鐨勮繛鎺?br>     if(conn == null){//濡傛灉娌℃湁鎵懼埌,鍒欒瘯鐫浜х敓鏂扮殑榪炴帴鏀懼叆姹犱腑<br>     for(int i = 1; connections.size() < maxCount && i <= rateCount;i++){//鏄惁鍐嶈兘鍦ㄨ繛鎺ユ睜涓鍔犺繛鎺ュ彇鍐充笌maxCount<br>     connections.add(newCharsConnection());<br>    }<br>    conn = findFreeConnection();//鍐嶆鍦ㄨ繛鎺ユ睜涓壘<br>  }  <br>   return conn;<br> }<br> /**<br>  * 鍦ㄦ睜涓煡鎵懼彲浠ヤ嬌鐢ㄧ殑榪炴帴<br>  * @return<br>  */<br> private Connection findFreeConnection()throws SQLException<br> {<br>     CharsPoolConnection charsConn = null;<br>     Connection conn = null;<br>     for(int i = 0; i < connections.size();i++){<br>     charsConn = (CharsPoolConnection)connections.get(i);<br>     if(charsConn.isBusy())continue;<br>     else {<br>         if(!isAvalidConnection(charsConn.getConnection())) {<br>          charsConn.setConnection(newConnection());<br>          }<br>      conn = charsConn.getConnection();//寰楀埌鍙互鐢ㄧ殑榪炴帴<br>      charsConn.setBusy(true);//琛ㄦ槑涓轟嬌鐢ㄧ姸鎬?br>      ACTIVE_ACOUNT++;<br>      break;<br>      }<br>    }<br>    return conn;<br> }<br> <br> /**<br>  * 鍒ゆ柇姹犱腑鐨勮繛鎺ユ槸鍚﹀洜涓哄叾浠栧師鍥犲彉寰椾笉鍙互鐢?br>  * @param conn<br>  * @return<br>  */<br> private boolean isAvalidConnection(Connection conn)<br> {<br>    try<br>    {<br>         conn.setAutoCommit(true);//妯℃嫙鍔ㄤ綔,濡傛灉鑳藉鑳藉鎿嶄綔鍒欒鏄庤榪炴帴鍙敤<br>     }catch(SQLException e)<br>    {<br>       closeConnection(conn);<br>       return false;<br>    }<br>    return true;<br> }<br> <br> /**<br>  * 鍒ゆ柇涓涓繛鎺ユ槸鍚﹁繕鍙互鐢?濡傛灉涓嶅彲浠ョ敤鍒欏垱寤轟竴涓柊鐨勮繛鎺ヤ唬鏇垮畠<br>  * @param conn<br>  * @return<br>  */<br> private CharsPoolConnection newCharsConnection()throws SQLException<br> {<br>  <br>     CharsPoolConnection charsCon = new CharsPoolConnection();<br>     charsCon.setConnection(newConnection());<br>     charsCon.setBusy(false);<br>  <br>     return charsCon;<br> }<br> /**<br>  * 鑾峰彇涓涓柊鐨勬暟鎹簱榪炴帴<br>  * @return<br>  * @throws SQLException<br>  */<br> private Connection newConnection()throws SQLException<br> {<br>      return DriverManager.getConnection(this.url,this.userName,this.password);<br> }<br> /**<br>  * 鍏抽棴鏁版嵁搴撹繛鎺?br>  * @param conn<br>  */<br> private void closeConnection(Connection conn)<br> {<br>  try<br>  {<br>       conn.close();<br>  }catch(SQLException se)<br>  {<br>      System.out.println("鍏抽棴榪炴帴鍙戠敓寮傚父...");<br>  }<br> }<br>}<br><br><br>灝佽榪炴帴姹犵殑榪炴帴:<br>package chars.pool;</p> <p>public class CharsPoolConnection<br>{<br>    private boolean isBusy;<br>    <br>    private java.sql.Connection connection;</p> <p>   public java.sql.Connection getConnection()<br>  {<br>       return connection;<br>  }</p> <p>  public void setConnection(java.sql.Connection connection)<br> {<br>      this.connection = connection;<br> }</p> <p> public boolean isBusy()<br> {<br>      return isBusy;<br> }</p> <p> public void setBusy(boolean isBusy)<br> {<br>      this.isBusy = isBusy;<br> }<br>}<br><br>璋冪敤鐨勬柟寮忓ぇ鑷村彲浠ヨ繖鏍?<br>    CharsConnectionPool pool = new CharsConnectionPool(env);<br>     pool.initiatePools();<br>    Connection conn= pool.getConnection(); //鑾峰彇榪炴帴<br>    //do something with your code;<br>    pool .rebackConnection(conn); 褰掕繕榪炴帴鍒拌繛鎺ユ睜</p> </blockquote> <img src ="http://www.aygfsteel.com/chars/aggbug/127644.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/chars/" target="_blank">chars</a> 2007-07-02 17:46 <a href="http://www.aygfsteel.com/chars/archive/2007/07/02/127644.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> 主站蜘蛛池模板: <a href="http://" target="_blank">玉门市</a>| <a href="http://" target="_blank">黄骅市</a>| <a href="http://" target="_blank">宁晋县</a>| <a href="http://" target="_blank">怀柔区</a>| <a href="http://" target="_blank">昌平区</a>| <a href="http://" target="_blank">霞浦县</a>| <a href="http://" target="_blank">雷山县</a>| <a href="http://" target="_blank">崇礼县</a>| <a href="http://" target="_blank">安阳市</a>| <a href="http://" target="_blank">江津市</a>| <a href="http://" target="_blank">汶川县</a>| <a href="http://" target="_blank">台北县</a>| <a href="http://" target="_blank">探索</a>| <a href="http://" target="_blank">盖州市</a>| <a href="http://" target="_blank">霸州市</a>| <a href="http://" target="_blank">尉犁县</a>| <a href="http://" target="_blank">镇坪县</a>| <a href="http://" target="_blank">永靖县</a>| <a href="http://" target="_blank">丽江市</a>| <a href="http://" target="_blank">九江县</a>| <a href="http://" target="_blank">云林县</a>| <a href="http://" target="_blank">道孚县</a>| <a href="http://" target="_blank">大连市</a>| <a href="http://" target="_blank">景泰县</a>| <a href="http://" target="_blank">安顺市</a>| <a href="http://" target="_blank">昌图县</a>| <a href="http://" target="_blank">岫岩</a>| <a href="http://" target="_blank">南汇区</a>| <a href="http://" target="_blank">博乐市</a>| <a href="http://" target="_blank">漳平市</a>| <a href="http://" target="_blank">东兰县</a>| <a href="http://" target="_blank">无极县</a>| <a href="http://" target="_blank">高安市</a>| <a href="http://" target="_blank">沿河</a>| <a href="http://" target="_blank">郑州市</a>| <a href="http://" target="_blank">揭阳市</a>| <a href="http://" target="_blank">锦屏县</a>| <a href="http://" target="_blank">呈贡县</a>| <a href="http://" target="_blank">拉萨市</a>| <a href="http://" target="_blank">黔西县</a>| <a href="http://" target="_blank">靖边县</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>