网站建设销售工作怎么样,做网站不用tomcat行吗,ps设计网站首页界面,发来贵州省建设厅网站ETL工具完毕的差点儿相同了。今天遇到一个问题。就是给C3P0配置了maxPoolSize为10。目的是想让整个应用同一时候获得的最大的Connection个数为10#xff0c;可是在測试应用的这一部分之后#xff0c;发现PostgreSQL端的链接远远超过10个。由于工具是多线程的。所以就想#… ETL工具完毕的差点儿相同了。今天遇到一个问题。就是给C3P0配置了maxPoolSize为10。目的是想让整个应用同一时候获得的最大的Connection个数为10可是在測试应用的这一部分之后发现PostgreSQL端的链接远远超过10个。由于工具是多线程的。所以就想是不是多线程的问题查了一下Connection的个数也确实是10*线程个数。于是做了一个測试 将maxPoolSize配置为5。执行以下的程序 ComboPooledDataSource cpds new ComboPooledDataSource(postgres);for (int i 0; i 10; i) {cpds.getConnection();}
ComboPooledDataSource cpds2 new ComboPooledDataSource(postgres);for (int i 0; i 10; i) {cpds2.getConnection();} maxPoolSize配置为5。一共想要获取20个链接这时查看PostgreSQL Server端的连接数为5正式预期的结果。 在执行以下的程序 for (int i 0; i 2; i) {new Thread(new Runnable() {Overridepublic void run() {ComboPooledDataSource cpds new ComboPooledDataSource(postgres);for (int i 0; i 10; i) {try {cpds.getConnection();} catch (SQLException e) {e.printStackTrace();}}try {Thread.sleep(100000);} catch (InterruptedException e) {e.printStackTrace();}}}, Thread i).start();} 两个线程每一个线程想要获取10个链接数这时查看PostgreSQL Server端的链接数是10个。将i2改为i3在执行一次查看PostgreSQL Server端的连接数是15。 再进行以下的測试 final ComboPooledDataSource cpds new ComboPooledDataSource(postgres);for (int i 0; i 3; i) {new Thread(new Runnable() {Overridepublic void run() {for (int i 0; i 10; i) {try {cpds.getConnection();} catch (SQLException e) {e.printStackTrace();}}try {Thread.sleep(100000);} catch (InterruptedException e) {e.printStackTrace();}}}, Thread i).start(); 创建3个线程每一个线程须要10个Connection这时查看PostgreSQL Server端的连接数是5。可见PostgreSQL Server端的链接的个数与client创建的ComboPooledDataSource实例的个数成正比。C3P0配置文件里配置的内容都是针对一个ComboPooledDataSource实例的限制。 结论 底层的原因大概是由于C3P0不是为多线程设计的在底层JDBC也不是线程安全的。详细的原因有机会在详细分析。 一个应用中一般一个数据源仅仅用一个ComboPooledDataSource对象也就是一个ComboPooledDataSource实例。 转载于:https://www.cnblogs.com/mengfanrong/p/5129613.html