c3p0

C3P0 Spring Hibernate: Pool maxed out. How to debug?

假如想象 提交于 2019-11-26 18:40:54
问题 I have a Spring Hibernate application on Tomcat. Connection pool is C3P0 I am rapidly encountering a thread pool maxed out warning from C3P0. Then all requests to the webapp hang. I am still assuming that somewhere in the code I have missed an @Transaction annotation. I want to debug my code. Question: Can I access the connection pool via code so I can debug when a connection is released and when it is not released? UPDATE: Current c3p0 config: <!-- Hibernate --> <bean id="dataSource" class=

com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source

泄露秘密 提交于 2019-11-26 17:47:25
问题 I have MySQL under my Hibernate and I am also using c3p0-0.9.1 for connection pool. When running on my laptop (I mean locally) I have no errors. But when I deploy it on the server, I get this exception: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source. This is my stack trace: root cause com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its

Spring JDBC connection pool best practices

允我心安 提交于 2019-11-26 17:36:00
问题 I have a basic Spring JDBC application with a pretty basic configuration: <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="oracle.jdbc.OracleDriver"/> <property name="url" value="jdbc:oracle:thin:@1.1.1.1:1521:XXX"/> <property name="username" value="username"/> <property name="password" value="password"/> </bean> <bean id="dbThing" class="com.DbThing"> <property name="dataSource" ref="myDataSource"/> </bean> I

SpringMVC+Mybatis 如何配置多个数据源并切换?

江枫思渺然 提交于 2019-11-26 16:55:39
最近公司一个项目需要连接两个数据库(A和B)操作,有的模块查询A库,有的模块查询B库,因此需要改造下,项目后台用的是SpringMVC+Mybatis+MySQL架构,折腾了两天后终于搞定了,在这里记录过改造过程。 使用场景 多数据源的使用的场景一般有: 主从数据库切换 读写分离 兼容旧库 实现原理 Spring2.x的版本中采用Proxy模式,就是在方案中实现一个虚拟的数据源,并且用它来封装数据源选择逻辑,这样就可以有效地将数据源选择逻辑从Client中分离出来。Client提供选择所需的上下文,由虚拟的DynamicDataSource根据Client提供的上下文来实现数据源的选择。 具体的实现是虚拟的DynamicDataSource仅需继承AbstractRoutingDataSource实现determineCurrentLookupKey(),该方法返回需要使用的DataSource的key值,然后根据这个key从resolvedDataSources这个map里取出对应的DataSource,如果找不到则用默认的resolvedDefaultDataSource。 详细实现过程 修改spring的配置文件 配置文件里需要配置多个数据源,改造后主要配置如下: <bean id="dataSourceTargetA" class="com.mchange.v2.c3p0

hibernate with c3p0: createClob() is not yet implemented

若如初见. 提交于 2019-11-26 16:44:01
问题 In my project I started to use c3p0 with hibernate for reconnecting to database as hibernate won't restore connection on db failure. <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-c3p0</artifactId> <version>5.2.9.Final</version> </dependency> I am using hibernate version: <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>5.2.9.Final</version> </dependency> the postgresql driver is: <dependency> <groupId>org.postgresql</groupId>

C3P0&Druid——两种数据库连接池的使用方法

烂漫一生 提交于 2019-11-26 14:03:00
数据库连接池——C3P0&Druid (一) 数据库连接池 每一个事物都有其存在的意义,在初学jdbc的时候,我们建立数据库连接对象后,会对其进行释放,但是数据库连接的建立和关闭是非常消耗资源的,而且频繁的操作会使得性能变得低下,数据库连接池可以帮我们解决这样的问题 (1) 概念 数据库连接池负责分配、管理和释放数据库连接,它允许应用程序重复使用一个现有的数据库连接,而不是再重新建立一个;释放空闲时间超过最大空闲时间的数据库连接来避免因为没有释放数据库连接而引起的数据库连接遗漏。这项技术能明显提高对数据库操作的性能。 简单理解:就是一个存放数据库连接的容器,当用户需要访问数据库的时候,容器提供连接对象给用户用,之后用户将连接对象归还给容器 (2) 使用 A :实现 javax.sql 包下的 DataSource 接口 方法:获取连接: getConnection() 方法:归还连接: Connection.close() 注意:在连接池中使用connection.close()方法,不代表关闭连接,代表归还连接 B :我们可以使用一些开源的数据库厂商提供的实现 C3P0 Druid (来自阿里巴巴) (3) C3P0 A :首先 导入三个jar包 c3p0-0.9.5.2.jar 、mchange-commons-java-0.2.12.jar、数据库驱动jar包 B

How to monitor c3p0 connections

本秂侑毒 提交于 2019-11-26 12:43:38
问题 I am using Hibernate in my JBoss war, using c3p0 for connection pooling, both configured within a hibernate.cfg.xml config file in my classpath <property name=\"connection.provider_class\">org.hibernate.connection.C3P0ConnectionProvider</property> I\'ve seen server.log generates lines with interesting information about the connection pool: DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] trace com.mchange.v2.resourcepool.BasicResourcePool@63f5e4b6 [managed: 10, unused: 9, excluded: 0]

Java JDBC connection pool library choice in 2011/2012?

落爺英雄遲暮 提交于 2019-11-26 07:56:00
问题 Which JDBC connection pool library should I use for a new application project (not web application)? Apache DBCP has enough unresolved issues which are pushed until 2.0 I think. C3P0 development seems to be stopped. And both of them looks relatively slow. Proxool is dead. DBPool has almost no community (at least I\'ve found no public one - no forums, no mailing lists...) Apache Tomcat Pool looks to be unusable without Tomcat I\'ve found SQL Datasources article at Oracle website, but it seems,

JDBC+C3P0+DBCP 基本使用

青春壹個敷衍的年華 提交于 2019-11-25 23:19:36
1.概述 这篇文章主要说了JDBC的基本使用,包括Statement,PreparedStatement,JDBC的连接,Mysql创建用户创建数据表,C3P0的连接与配置,DBCP的连接与配置. 2.mysql的处理 这里的JDBC使用Mysql作为DBMS,请先安装Mysql,未安装的 请点击这里下载 , 安装教程在这里 ,作者使用的Mysql的8.0.17版本. (1)新建用户 随便新建一个用户,比如这里作者新建的是aa,密码是aa123bb. create user 'aa'@'localhost' identified by 'aa123bb' (2)建立数据表 建立测试用的数据表与数据库. create database db; use db; create table db ( id int PRIMARY key, name char(20) ); (3)用户权限 对刚才新建的用户授权: grant select,update,delete,insert on db.* to 'aa'@'localhost'; 2.JDBC (1)jar包 8.0.17版本在这里 各个版本的在这里下载 (2)连接 首先注册驱动,驱动需要一个url,用户名和密码,用户名和密码是上一步创建好的,url包含ip地址,端口和数据库的名字. private static final

Connection pooling options with JDBC: DBCP vs C3P0

 ̄綄美尐妖づ 提交于 2019-11-25 22:45:30
问题 What is the best connection pooling library available for Java/JDBC? I\'m considering the 2 main candidates (free / open-source): Apache DBCP - http://commons.apache.org/dbcp/ C3P0 - http://sourceforge.net/projects/c3p0 I\'ve read a lot about them in blogs and other forums but could not reach a decision. Are there any relevant alternatives to these two? 回答1: DBCP is out of date and not production grade. Some time back we conducted an in-house analysis of the two, creating a test fixture which