锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品乱战久久久,成人综合影院,暧暧视频在线免费观看 http://www.aygfsteel.com/looline/category/16970.html姘告亽鐨勬ゼ鍏?/description>zh-cn Tue, 27 Feb 2007 12:26:36 GMT Tue, 27 Feb 2007 12:26:36 GMT 60 鍔熻兘瀹屽杽鐨凧ava榪炴帴姹犺皟鐢ㄥ疄渚?/title> http://www.aygfsteel.com/looline/articles/86355.htmllooline looline Fri, 08 Dec 2006 07:15:00 GMT http://www.aygfsteel.com/looline/articles/86355.html http://www.aygfsteel.com/looline/comments/86355.html http://www.aygfsteel.com/looline/articles/86355.html#Feedback 0 http://www.aygfsteel.com/looline/comments/commentRss/86355.html http://www.aygfsteel.com/looline/services/trackbacks/86355.html
--------------------------- /** * Title: ConnectPool.java * Description: 榪炴帴姹犵鐞嗗櫒 * Copyright: Copyright (c) 2002/12/25 * Company: * Author : * Version 2.0 */ import java.io.*; import java.sql.*; import java.util.*; import java.util.Date; /** * 綆$悊綾籇BConnectionManager鏀寔瀵逛竴涓垨澶氫釜鐢卞睘鎬ф枃浠跺畾涔夌殑鏁版嵁搴撹繛鎺? * 姹犵殑璁塊棶.瀹㈡埛紼嬪簭鍙互璋冪敤getInstance()鏂規(guī)硶璁塊棶鏈被鐨勫敮涓瀹炰緥. */ public class ConnectPool { static public ConnectPool instance; // 鍞竴瀹炰緥 static public int clients; public Vector drivers = new Vector(); //椹卞姩 public PrintWriter log; public Hashtable pools = new Hashtable(); //榪炴帴 /** * 榪斿洖鍞竴瀹炰緥.濡傛灉鏄涓嬈¤皟鐢ㄦ鏂規(guī)硶,鍒欏垱寤哄疄渚? * * @return DBConnectionManager 鍞竴瀹炰緥 */ static synchronized public ConnectPool getInstance() { if (instance == null) { instance = new ConnectPool(); } clients++; return instance; } /** * 寤烘瀯鍑芥暟縐佹湁浠ラ槻姝㈠叾瀹冨璞″垱寤烘湰綾誨疄渚? */ public ConnectPool() { init(); } /** * 灝嗚繛鎺ュ璞¤繑鍥炵粰鐢卞悕瀛楁寚瀹氱殑榪炴帴姹? * * @param name 鍦ㄥ睘鎬ф枃浠朵腑瀹氫箟鐨勮繛鎺ユ睜鍚嶅瓧 * @param con 榪炴帴瀵硅薄 */ public void freeConnection(String name, Connection con) { DBConnectionPool pool = (DBConnectionPool) pools.get(name); if (pool != null) { pool.freeConnection(con); } else { System.out.println("pool ==null"); } clients--; } /** * 鑾峰緱涓涓彲鐢ㄧ殑(絀洪棽鐨?榪炴帴.濡傛灉娌℃湁鍙敤榪炴帴,涓斿凡鏈夎繛鎺ユ暟灝忎簬鏈澶ц繛鎺ユ暟 * 闄愬埗,鍒欏垱寤哄茍榪斿洖鏂拌繛鎺? * * @param name 鍦ㄥ睘鎬ф枃浠朵腑瀹氫箟鐨勮繛鎺ユ睜鍚嶅瓧 * @return Connection 鍙敤榪炴帴鎴杗ull */ public Connection getConnection(String name) { DBConnectionPool pool = (DBConnectionPool) pools.get(name); if (pool != null) { //return pool.getConnection(); return pool.returnConnection(); } return null; } /** * 鑾峰緱涓涓彲鐢ㄨ繛鎺?鑻ユ病鏈夊彲鐢ㄨ繛鎺?涓斿凡鏈夎繛鎺ユ暟灝忎簬鏈澶ц繛鎺ユ暟闄愬埗, * 鍒欏垱寤哄茍榪斿洖鏂拌繛鎺?鍚﹀垯,鍦ㄦ寚瀹氱殑鏃墮棿鍐呯瓑寰呭叾瀹冪嚎紼嬮噴鏀捐繛鎺? * * @param name 榪炴帴姹犲悕瀛? * @param time 浠ユ縐掕鐨勭瓑寰呮椂闂? * @return Connection 鍙敤榪炴帴鎴杗ull */ public Connection getConnection(String name, long time) { DBConnectionPool pool = (DBConnectionPool) pools.get(name); if (pool != null) { return pool.getConnection(time); } return null; } /** * 鍏抽棴鎵鏈夎繛鎺?鎾ら攢椹卞姩紼嬪簭鐨勬敞鍐? */ public synchronized void release() { // 絳夊緟鐩村埌鏈鍚庝竴涓鎴風(fēng)▼搴忚皟鐢? if (--clients != 0) { return; } Enumeration allPools = pools.elements(); while (allPools.hasMoreElements()) { DBConnectionPool pool = (DBConnectionPool) allPools.nextElement(); pool.release(); } Enumeration allDrivers = drivers.elements(); while (allDrivers.hasMoreElements()) { Driver driver = (Driver) allDrivers.nextElement(); try { DriverManager.deregisterDriver(driver); log("鎾ら攢JDBC椹卞姩紼嬪簭 " + driver.getClass().getName()+"鐨勬敞鍐?); } catch (SQLException e) { log(e, "鏃犳硶鎾ら攢涓嬪垪JDBC椹卞姩紼嬪簭鐨勬敞鍐? " + driver.getClass().getName()); } } } /** * 鏍規(guī)嵁鎸囧畾灞炴у垱寤鴻繛鎺ユ睜瀹炰緥. * * @param props 榪炴帴姹犲睘鎬? */ private void createPools(Properties props) { Enumeration propNames = props.propertyNames(); while (propNames.hasMoreElements()) { String name = (String) propNames.nextElement(); if (name.endsWith(".url")) { String poolName = name.substring(0, name.lastIndexOf(".")); String url = props.getProperty(poolName + ".url"); if (url == null) { log("娌℃湁涓鴻繛鎺ユ睜" + poolName + "鎸囧畾URL"); continue; } String user = props.getProperty(poolName + ".user"); String password = props.getProperty(poolName + ".password"); String maxconn = props.getProperty(poolName + ".maxconn", "0"); int max; try{ max = Integer.valueOf(maxconn).intValue(); } catch (NumberFormatException e) { log("閿欒鐨勬渶澶ц繛鎺ユ暟闄愬埗: " + maxconn + " .榪炴帴姹? " + poolName); max = 0; } DBConnectionPool pool = new DBConnectionPool(poolName, url, user, password, max); pools.put(poolName, pool); log("鎴愬姛鍒涘緩榪炴帴姹? + poolName); } } } /** * 璇誨彇灞炴у畬鎴愬垵濮嬪寲 */ private void init() { try { Properties p = new Properties(); String configs = System.getProperty("user.dir")+"\conf\db.properties"; System.out.println("configs file local at "+configs); FileInputStream is = new FileInputStream(configs); Properties dbProps = new Properties(); try { dbProps.load(is); } catch (Exception e) { System.err.println("涓嶈兘璇誨彇灞炴ф枃浠? " +"璇風(fēng)‘淇漝b.properties鍦–LASSPATH鎸囧畾鐨勮礬寰勪腑"); return; } String logFile = dbProps.getProperty("logfile", "DBConnectionManager.log"); try{ log = new PrintWriter(new FileWriter(logFile, true), true); } catch (IOException e) { System.err.println("鏃犳硶鎵撳紑鏃ュ織鏂囦歡: " + logFile); log = new PrintWriter(System.err); } loadDrivers(dbProps); createPools(dbProps); }catch(Exception e){} } /** 171 * 瑁呰澆鍜屾敞鍐屾墍鏈塉DBC椹卞姩紼嬪簭 172 * 173 * @param props 灞炴? 174 */ private void loadDrivers(Properties props) { String driverClasses = props.getProperty("drivers"); StringTokenizer st = new StringTokenizer(driverClasses); while (st.hasMoreElements()) { String driverClassName = st.nextToken().trim(); try{ Driver driver = (Driver) Class.forName(driverClassName).newInstance(); DriverManager.registerDriver(driver); drivers.addElement(driver); System.out.println(driverClassName); log("鎴愬姛娉ㄥ唽JDBC椹卞姩紼嬪簭" + driverClassName); } catch (Exception e) { log("鏃犳硶娉ㄥ唽JDBC椹卞姩紼嬪簭: " + driverClassName + ", 閿欒: " + e); } } } /** * 灝嗘枃鏈俊鎭啓鍏ユ棩蹇楁枃浠? */ private void log(String msg) { log.println(new Date() + ": " + msg); } /** * 灝嗘枃鏈俊鎭笌寮傚父鍐欏叆鏃ュ織鏂囦歡 */ private void log(Throwable e, String msg) { log.println(new Date() + ": " + msg); e.printStackTrace(log); } /** * 姝ゅ唴閮ㄧ被瀹氫箟浜嗕竴涓繛鎺ユ睜.瀹冭兘澶熸牴鎹姹傚垱寤烘柊榪炴帴,鐩村埌棰勫畾鐨勬渶 * 澶ц繛鎺ユ暟涓烘.鍦ㄨ繑鍥炶繛鎺ョ粰瀹㈡埛紼嬪簭涔嬪墠,瀹冭兘澶熼獙璇佽繛鎺ョ殑鏈夋晥鎬? */ class DBConnectionPool { //private int checkedOut; private Vector freeConnections = new Vector(); private int maxConn; private String name; private String password; private String URL; private String user; /** * 鍒涘緩鏂扮殑榪炴帴姹? * * @param name 榪炴帴姹犲悕瀛? * @param URL 鏁版嵁搴撶殑JDBC URL * @param user 鏁版嵁搴撳笎鍙?鎴?null * @param password 瀵嗙爜,鎴?null * @param maxConn 姝よ繛鎺ユ睜鍏佽寤虹珛鐨勬渶澶ц繛鎺ユ暟 */ public DBConnectionPool(String name, String URL, String user, String password,int maxConn) { this.name = name; this.URL = URL; this.user = user; this.password = password; this.maxConn = maxConn; } /** * 灝嗕笉鍐嶄嬌鐢ㄧ殑榪炴帴榪斿洖緇欒繛鎺ユ睜 * * @param con 瀹㈡埛紼嬪簭閲婃斁鐨勮繛鎺? */ public synchronized void freeConnection(Connection con) { // 灝嗘寚瀹氳繛鎺ュ姞鍏ュ埌鍚戦噺鏈熬 try { if(con.isClosed()){System.out.println("before freeConnection con is closed");} freeConnections.addElement(con); Connection contest = (Connection) freeConnections.lastElement(); if(contest.isClosed()){System.out.println("after freeConnection contest is closed");} notifyAll(); }catch(SQLException e){System.out.println(e);} } /** * 浠庤繛鎺ユ睜鑾峰緱涓涓彲鐢ㄨ繛鎺?濡傛病鏈夌┖闂茬殑榪炴帴涓斿綋鍓嶈繛鎺ユ暟灝忎簬鏈澶ц繛鎺? * 鏁伴檺鍒?鍒欏垱寤烘柊榪炴帴.濡傚師鏉ョ櫥璁頒負(fù)鍙敤鐨勮繛鎺ヤ笉鍐嶆湁鏁?鍒欎粠鍚戦噺鍒犻櫎涔? * 鐒跺悗閫掑綊璋冪敤鑷繁浠ュ皾璇曟柊鐨勫彲鐢ㄨ繛鎺? */ public synchronized Connection getConnection() { Connection con = null; if (freeConnections.size() > 0) { // 鑾峰彇鍚戦噺涓涓涓彲鐢ㄨ繛鎺? con = (Connection) freeConnections.firstElement(); freeConnections.removeElementAt(0); try { if (con.isClosed()) { log("浠庤繛鎺ユ睜" + name+"鍒犻櫎涓涓棤鏁堣繛鎺?); System.out.println("浠庤繛鎺ユ睜" + name+"鍒犻櫎涓涓棤鏁堣繛鎺?); // 閫掑綊璋冪敤鑷繁,灝濊瘯鍐嶆鑾峰彇鍙敤榪炴帴 con = getConnection(); } } catch (SQLException e) { log("浠庤繛鎺ユ睜" + name+"鍒犻櫎涓涓棤鏁堣繛鎺ユ椂閿欒"); System.out.println("浠庤繛鎺ユ睜" + name+"鍒犻櫎涓涓棤鏁堣繛鎺ュ嚭閿?); // 閫掑綊璋冪敤鑷繁,灝濊瘯鍐嶆鑾峰彇鍙敤榪炴帴 con = getConnection(); } if(freeConnections.size()>maxConn) { System.out.println(" 鍒犻櫎涓涓孩鍑鴻繛鎺?"); releaseOne(); } } else if((maxConn == 0)||(freeConnections.size()<maxConn)) { con = newConnection(); } return con; } public synchronized Connection returnConnection() { Connection con = null; //濡傛灉闂茬疆灝忎簬鏈澶ц繛鎺?榪斿洖涓涓柊榪炴帴 if(freeConnections.size()<maxConn) { con = newConnection(); } //濡傛灉闂茬疆澶т簬鏈澶ц繛鎺ワ紝榪斿洖涓涓彲鐢ㄧ殑鏃ц繛鎺? else if(freeConnections.size()>=maxConn) { con = (Connection) freeConnections.firstElement(); System.out.println(" [a 榪炴帴姹犲彲鐢ㄨ繛鎺ユ暟 ] : "+"[ "+freeConnections.size()+" ]"); freeConnections.removeElementAt(0); System.out.println(" [b 榪炴帴姹犲彲鐢ㄨ繛鎺ユ暟 ] : "+"[ "+freeConnections.size()+" ]"); try { if (con.isClosed()) { log("浠庤繛鎺ユ睜" + name+"鍒犻櫎涓涓棤鏁堣繛鎺?); System.out.println("浠庤繛鎺ユ睜" + name+"鍒犻櫎涓涓棤鏁堣繛鎺?); returnConnection(); } }catch (SQLException e) { log("浠庤繛鎺ユ睜" + name+"鍒犻櫎涓涓棤鏁堣繛鎺ユ椂閿欒"); System.out.println("浠庤繛鎺ユ睜" + name+"鍒犻櫎涓涓棤鏁堣繛鎺ュ嚭閿?); returnConnection(); } } return con; } /** * 浠庤繛鎺ユ睜鑾峰彇鍙敤榪炴帴.鍙互鎸囧畾瀹㈡埛紼嬪簭鑳藉絳夊緟鐨勬渶闀挎椂闂? * 鍙傝鍓嶄竴涓猤etConnection()鏂規(guī)硶. * * @param timeout 浠ユ縐掕鐨勭瓑寰呮椂闂撮檺鍒? */ public synchronized Connection getConnection(long timeout) { long startTime = new Date().getTime(); Connection con; while ((con = getConnection()) == null) { try { wait(timeout); } catch (InterruptedException e) {} if ((new Date().getTime() - startTime) >= timeout) { // wait()榪斿洖鐨勫師鍥犳槸瓚呮椂 return null; } } return con; } /** * 鍏抽棴鎵鏈夎繛鎺? */ public synchronized void release() { Enumeration allConnections = freeConnections.elements(); while (allConnections.hasMoreElements()) { Connection con = (Connection) allConnections.nextElement(); try { con.close(); log("鍏抽棴榪炴帴姹? + name+"涓殑涓涓繛鎺?); } catch (SQLException e) { log(e, "鏃犳硶鍏抽棴榪炴帴姹? + name+"涓殑榪炴帴"); } } freeConnections.removeAllElements(); } /** * 鍏抽棴涓涓繛鎺? */ public synchronized void releaseOne() { if(freeConnections.firstElement()!=null) { Connection con = (Connection) freeConnections.firstElement(); try { con.close(); System.out.println("鍏抽棴榪炴帴姹? + name+"涓殑涓涓繛鎺?); log("鍏抽棴榪炴帴姹? + name+"涓殑涓涓繛鎺?); } catch (SQLException e) { System.out.println("鏃犳硶鍏抽棴榪炴帴姹? + name+"涓殑涓涓繛鎺?); log(e, "鏃犳硶鍏抽棴榪炴帴姹? + name+"涓殑榪炴帴"); } } else { System.out.println("releaseOne() bug......................................................."); } } /** * 鍒涘緩鏂扮殑榪炴帴 */ private Connection newConnection() { Connection con = null; try { if (user == null) { con = DriverManager.getConnection(URL); } else{ con = DriverManager.getConnection(URL, user, password); } log("榪炴帴姹? + name+"鍒涘緩涓涓柊鐨勮繛鎺?); } catch (SQLException e) { log(e, "鏃犳硶鍒涘緩涓嬪垪URL鐨勮繛鎺? " + URL); return null; } return con; } } } ================================ /** * Title: ConnectPool.java * Description: 鏁版嵁搴撴搷浣? * Copyright: Copyright (c) 2002/12/25 * Company: * Author : * remark : 鍔犲叆鎸囬拡鍥炴粴 * Version 2.0 */ import java.io.*; import com.sjky.pool.*; import java.sql.*; import java.util.*; import java.util.Date; import java.net.*; public class PoolMan extends ConnectPool { private ConnectPool connMgr; private Statement stmt; private Connection con ; private ResultSet rst; /** *瀵硅薄榪炴帴鍒濆鍖? * */ public Connection getPool(String name) throws Exception { try{ connMgr = ConnectPool.getInstance(); con = connMgr.getConnection(name); }catch(Exception e) { System.err.println("涓嶈兘鍒涘緩榪炴帴!璇峰皾璇曢噸鍚簲鐢ㄦ湇鍔″櫒"); } return con; } /** *鍚屼互涓婃柟娉?鍔犲叆榪炴帴絀洪棽絳夊緟鏃墮棿 *寰呯敤鏂規(guī)硶 * */ public Connection getPool_t(String name, long time) throws Exception { try{ connMgr = ConnectPool.getInstance(); con = connMgr.getConnection(name,time); }catch(Exception e) { System.err.println("涓嶈兘鍒涘緩榪炴帴!"); } return con; } /** *鎵ц鏌ヨ鏂規(guī)硶1 * */ public ResultSet executeQuery(String SqlStr) throws Exception { ResultSet result = null; try { stmt = con.createStatement(); result = stmt.executeQuery(SqlStr); // here add one line by jnma 12.11 con.commit(); } catch(java.sql.SQLException e) { throw new Exception("鎵ц鏌ヨ璇彞鍑洪敊"); } return result; } /** *鎵ц鏌ヨ鏂規(guī)硶2 * */ public ResultSet getRst(String SqlStr) throws Exception { // ResultSet result = null; try { stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); rst = stmt.executeQuery(SqlStr); // here add one line by jnma 12.11 con.commit(); } catch(java.sql.SQLException e) { throw new Exception("鎵ц鏌ヨ璇彞鍑洪敊"); } return rst; } /** *鎵ц鏇存柊 * */ public int Update(String SqlStr) throws Exception { int result = -1; try { stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); result = stmt.executeUpdate(SqlStr); // here add one line by jnma 12.11 con.commit(); if(result==0) System.out.println("鎵цdelete,update,insert SQL鍑洪敊"); } catch(java.sql.SQLException e) { System.err.println("鎵цdelete,update,insert SQL鍑洪敊"); } return result; } /** *鎵ц浜嬪姟澶勭悊 * */ public boolean handleTransaction(Vector SqlArray) throws Exception { boolean result = false; int ArraySize = SqlArray.size(); try { stmt = con.createStatement(); con.setAutoCommit(false); System.out.println("ArraySize is" +ArraySize); for(int i=0;i<ArraySize;i++) { System.out.println(" 寮濮嬫墽琛岃鍙?+(String)SqlArray.elementAt(i)); stmt.executeUpdate((String)SqlArray.elementAt(i)); System.out.println(" 鎵ц鎴愬姛"); } con.commit(); con.setAutoCommit(true) ;//蹇呴』 System.out.println("浜嬪姟鎵ц鎴愬姛"); result = true; } catch(java.sql.SQLException e) { try { System.out.println(e.toString()); System.out.println("鏁版嵁搴撴搷浣滃け璐?); con.rollback(); } catch(java.sql.SQLException Te) { System.err.println("浜嬪姟鍑洪敊鍥炴粴寮傚父"); } } try { con.setAutoCommit(true); } catch(java.sql.SQLException e) { System.err.println("璁劇疆鑷姩鎻愪氦澶辮觸"); } return result; } /** *閲婃斁榪炴帴 * */ public void close(String name) throws Exception { try { if(stmt!=null) stmt.close(); if(con!=null) { connMgr.freeConnection(name,con); System.out.println(" [c 姝e湪閲婃斁涓涓繛鎺?] "); } } catch(java.sql.SQLException e) { System.err.println("閲婃斁榪炴帴鍑洪敊"); } } } =========================== 灞炴ф枃浠禿b.properties鏀懼湪conf涓? #drivers=com.inet.tds.TdsDriver #logfile=c:\resin-2.1.4\DBConnectPool-log.txt #test.maxconn=1000 #test.url=jdbc:inetdae:SERVER:1433?sql7=true #test.user=sa #test.password=test drivers=com.microsoft.jdbc.sqlserver.SQLServerDriver logfile=F:\resin-2.1.4\DBConnectPool-log.txt test.maxconn=20 test.url=jdbc:microsoft:sqlserver://192.168.0.5:1433;DatabaseName=test test.user=sa test.password=test #drivers=oracle.jdbc.driver.OracleDriver #logfile=c:\resin-2.1.4\DBConnectPool-log.txt #test.maxconn=100 #test.url=jdbc:oracle:thin:@192.168.0.10:1521:myhome #test.user=system #test.password=manager #mysql绔?306 #drivers=org.gjt.mm.mysql.Driver #logfile=c:\resin-2.1.4\DBConnectPool-log.txt #test.maxconn=100 #test.url=jdbc:mysql://192.168.0.4:3306/my_test #test.user=root #test.password=system ]]>
主站蜘蛛池模板:
延长县 |
漯河市 |
彭州市 |
横峰县 |
泸西县 |
长宁县 |
渝北区 |
加查县 |
吴旗县 |
石棉县 |
鹰潭市 |
和硕县 |
汉源县 |
盐山县 |
晋宁县 |
金湖县 |
聂荣县 |
玉田县 |
固镇县 |
德江县 |
辽阳市 |
桑植县 |
奎屯市 |
呼图壁县 |
汉源县 |
勐海县 |
高雄县 |
育儿 |
呼伦贝尔市 |
金川县 |
信宜市 |
宣恩县 |
淳安县 |
涿鹿县 |
任丘市 |
长宁县 |
黄梅县 |
浮山县 |
彭州市 |
汾西县 |
乐业县 |