- 浏览: 304624 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
lzz3717845:
有道理,受教了~谢谢
关于SQL中自动增长列值回复(还原)的问题 -
桃汁天天:
ExtJs中如何动态设置其选中状态!! -
sangumaolv2:
你TM在说什么啊。。。。
关于SQL中自动增长列值回复(还原)的问题 -
duyupeng:
你好,我最近也是在使用这个控件,只是用了_id、_parent ...
ExtJs 中的TreeGrid(Ext.ux.maximgb.tg.EditorGridPanel详解与其他问题解决办法) -
wokao_wg:
大伙可以看看作者说的http://www.sencha.com ...
ExtJs 中的TreeGrid(Ext.ux.maximgb.tg.EditorGridPanel详解与其他问题解决办法)2
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; import java.util.Vector; public class PersonDefine_ConnectionPool implements Runnable { public String ProductionDB = "axdb_tmp";//給的默認值 private String database_driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";//給的默認值 // private String // dakabase_url="jdbc:sybase:Tds:IP:port/dakabase_test?useUnicode=true&characterEncoding=UTF-8"; private String database_url = "jdbc:sqlserver://localhost:1433;DatabaseName=mgr_live"; //給的默認值 private String username = "sa"; private String password = "12345678"; private int maxConnections = 50; private boolean waitIfBusy = true; private Vector availableConnections, busyConnections; private boolean connectionPending = false; public PersonDefine_ConnectionPool(Properties props) throws SQLException { System.out.println("jdbc:PersonDefine_ConnectionPool..."); int initialConnections = 0; this.ProductionDB = props.getProperty("ELITEDATA.ProductionDB"); this.database_driver = props.getProperty("ELITEDATA.database_driver").trim(); this.database_url = props.getProperty("ELITEDATA.database_url"); this.username=props.getProperty("ELITEDATA.database_username"); this.password=props.getProperty("ELITEDATA.database_password"); this.maxConnections = maxConnections; this.waitIfBusy = waitIfBusy; if (initialConnections > maxConnections) { initialConnections = maxConnections; } availableConnections = new Vector(initialConnections); busyConnections = new Vector(); for (int i = 0; i < initialConnections; i++) { availableConnections.addElement(makeNewConnection()); } } public synchronized Connection getConnection() throws SQLException { System.out.println("jdbc:Get PersonDefine_ConnectionPool..."); if (!availableConnections.isEmpty()) { Connection existingConnection = (Connection) availableConnections.lastElement(); int lastIndex = availableConnections.size() - 1; availableConnections.removeElementAt(lastIndex); // If connection on available list is closed (e.g., // it timed out), then remove it from available list // and repeat the process of obtaining a connection. // Also wake up threads that were waiting for a // connection because maxConnection limit was reached. if (existingConnection.isClosed()) { notifyAll(); // Freed up a spot for anybody waiting return (getConnection()); } else { busyConnections.addElement(existingConnection); return (existingConnection); } } else { // Three possible cases: // 1) You haven't reached maxConnections limit. So // establish one in the background if there isn't // already one pending, then wait for // the next available connection (whether or not // it was the newly established one). // 2) You reached maxConnections limit and waitIfBusy // flag is false. Throw SQLException in such a case. // 3) You reached maxConnections limit and waitIfBusy // flag is true. Then do the same thing as in second // part of step 1: wait for next available connection. if ((totalConnections() < maxConnections) && !connectionPending) { makeBackgroundConnection(); } else if (!waitIfBusy) { throw new SQLException("PersonDefine_ConnectionPool limit reached"); } // Wait for either a new connection to be established // (if you called makeBackgroundConnection) or for // an existing connection to be freed up. try { wait(); } catch (InterruptedException ie) { } // Someone freed up a connection, so try again. return (getConnection()); } } // You can't just make a new connection in the foreground // when none are available, since this can take several // seconds with a slow network connection. Instead, // start a thread that establishes a new connection, // then wait. You get woken up either when the new connection // is established or if someone finishes with an existing // connection. private void makeBackgroundConnection() { connectionPending = true; System.out.println("jdbc:Make Background PersonDefine_ConnectionPool..."); try { Thread connectThread = new Thread(this); connectThread.start(); } catch (OutOfMemoryError oome) { System.out.println("jdbc:PersonDefine_ConnectionPool out of Memory..." + oome); } } public void run() { try { System.out.println("jdbc:run PersonDefine_ConnectionPool..."); Connection connection = makeNewConnection(); synchronized (this) { availableConnections.addElement(connection); connectionPending = false; notifyAll(); } } catch (Exception e) { // SQLException or OutOfMemory System.out.println("jdbc:PersonDefine_ConnectionPool out of Memory..."); } } // This explicitly makes a new connection. Called in // the foreground when initializing the ConnectionPool, // and called in the background when running. private Connection makeNewConnection() throws SQLException { try { System.out.println("jdbc:make new PersonDefine_ConnectionPool..."); // Load database dakabase_driver if not already loaded Class.forName(database_driver); // Establish network connection to database Connection connection = DriverManager.getConnection(database_url, username, password); return (connection); } catch (ClassNotFoundException cnfe) { // Simplify try/catch blocks of people using this by // throwing only one exception type. System.out.println("jdbc:PersonDefine_ConnectionPool Can't find class for database_driver:"); throw new SQLException("Can't find class for PersonDefine_ConnectionPool: " + database_driver); } } public synchronized void free(Connection connection) { System.out.println("jdbc:free PersonDefine_ConnectionPool..."); busyConnections.removeElement(connection); availableConnections.addElement(connection); // Wake up threads that are waiting for a connection notifyAll(); } public synchronized int totalConnections() { return (availableConnections.size() + busyConnections.size()); } /** * Close all the connections. Use with caution: be sure no connections are * in use before calling. Note that you are not <I>required</I> to call * this when done with a ConnectionPool, since connections are guaranteed to * be closed when garbage collected. But this method gives more control * regarding when the connections are closed. */ public synchronized void closeAllConnections() { System.out.println("jdbc:close all PersonDefine_ConnectionPool..."); closeConnections(availableConnections); availableConnections = new Vector(); closeConnections(busyConnections); busyConnections = new Vector(); } private void closeConnections(Vector connections) { try { System.out.println("jdbc:close PersonDefine_ConnectionPool..."); for (int i = 0; i < connections.size(); i++) { Connection connection = (Connection) connections.elementAt(i); if (!connection.isClosed()) { connection.close(); } } } catch (SQLException sqle) { System.out.println("jdbc: PersonDefine_ConnectionPool..." + sqle); } } public synchronized String toString() { String info = "ConnectionPool(PersonDefine_ConnectionPool)(" + database_url + "," + username + ")" + ", available=" + availableConnections.size() + ", busy=" + busyConnections.size() + ", max=" + maxConnections; return (info); } }
发表评论
-
P6Spy应用:Hibernate显示真正SQL(3)
2012-08-03 18:44 1182更改p6spy.jar中的以下文件即可控制FileLogger ... -
P6Spy应用:Hibernate显示真正SQL(2)
2012-08-03 18:14 1373下表列出了 spy.properties 配置文件 ... -
P6Spy应用:Hibernate显示真正SQL(1)
2012-08-03 18:05 1591P6 ... -
ResultSet用法集锦
2012-02-23 16:56 139606ResultSet用法集锦 结 ... -
ResultSet 参数設置使用實例
2012-02-23 14:32 1100public static String[][] ... -
可供参考的【数据库连接池(DBCP)】
2012-02-10 10:10 955package com.spring.test; ... -
类型检查(RTTI与反射机制)转载
2012-02-02 10:35 1104... -
Servlet 3.0 新特性概览
2012-01-30 15:14 967Se ... -
如何在web.xml文件中引入其他的xml文件(web.xml如何拆分)
2011-11-14 20:08 8015如何在web.xm ... -
URL的Encoder、Decoder
2011-09-14 17:47 916URL : java.net.URLEncoder.e ... -
java中的DateAdd
2011-04-18 21:58 2292/** * 追溯到 startDate ... -
ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE
2011-04-18 21:52 2302Statement stmt = con.createSt ... -
都是空格惹得祸
2010-10-28 11:06 1112在一个属性文件中获取相关信息时:如 database.p ... -
SVN提交工作时需要注意的事项
2010-10-14 20:31 911一.提交之前先更新 1. ...
相关推荐
开源数据库连接池dbcp及其文档
数据库连接池DBCPjar包,数据库连接时.我们要是用到了数据库连接池,你需要的
数据库连接池dbcp.docx ( 数据库连接池dbcp.docx )
里面有dbcp以及其依赖的jar包和c3p0jar包。可以通过使用数据库链接池,高效、安全的复用,避免了数据库连接频繁建立、关闭的开销。
DBCP 数据库连接池 DBCP 数据库连接池 DBCP 数据库连接池 里面是DBCP的jar,导进去就可以用了
JDBC数据库连接池DBCP jsp页面直接获取DAO层数据 demo
java数据库连接池的开源版,dbcp,很好用,经过测试后个人觉得比较好配置。
DBCP配置数据库连接池实现对数据库的连接并附上增删改查
数据库连接池是 apache 上的一个 java 连接池项目,也是 tomcat 使用的连接池组件。在整合开发框架时会用得到
dbcp数据库连接池需要用到的jar,包括源码和api文档,javadoc
DBCP(DataBase Connection Pool)数据库连接池,是java数据库连接池的一种,由Apache开发,通过数据库连接池,可以让程序自动管理数据库连接的释放和断开。
适合学习练习用jar包
DBCP数据库连接池的完整jar包
java web开发 dbcp数据库连接池 所用jar包。java web开发 dbcp数据库连接池 所用jar包。
dbcp数据库连接池用到的jar包,在spring4整合过程中测试通过。
单独使用dbcp需要3个包:commons-dbcp.jar,commons-pool.jar,commons-collections.jar由于建立数据库连接是一个非常耗时耗资源的行为,所以通过连接池预先同数据库建立一些连接,放在内存中,应用程序需要建立数据库...
Apache的DBCP数据库连接池,好用的压缩包。凑字数凑字数
提供了数据库连接池的驱动,分别有c3p0、druid、dbcp三种数据库连接池的驱动
收集了常见的数据库连接jar包,包括oracle、mysql、sql server、db2、opta、dbcp连接池、c3p0连接池等等常见的数据库jar包,不断更新中。
Druid为监控而生的数据库连接池,它是阿里巴巴开源平台上的一个项目。Druid是Java语言中最好的数据库连接池,Druid能够提供强大的监控和扩展功能....Druid提供了一个高效、功能强大、可扩展性好的数据库连接池