c3p0

Hibernate / MySQL connection timeouts — Trying to deal with thread-pooled executors not releasing Hibernate connections to C3P0 after exit

南笙酒味 提交于 2019-12-05 06:03:10
I have a Tomcat application that uses MySQL, and Hibernate for ORM. The nature of our application demands that we have to pull and aggregate a lot of analytics data from a NoSQL store for each request , so we split the pulling and aggregating for each request into several tasks and delegate those to a thread-pooled executor service. When each thread performs a task, it needs to query / update MySQL regarding certain things so it borrows Hibernate sessions from C3P0 ( which we use for connection pooling ). Essential config : <property name="current_session_context_class">thread</property>

Zombie Connections to MySQL using c3p0 with tomcat

非 Y 不嫁゛ 提交于 2019-12-05 04:52:06
问题 I'm using c3p0 to manage my Database Connections to MySQL. The problem is that some connections are being hold forever. I have a limit of 1000 connections, but for some unknown reason, there are 1200 open connections. To investigate it, I do this command in the tomcat server shell: netstat -n |grep 3306|grep ESTABILISHED|wc -l and it returns 1200 here is the c3p0 configuration in context.xml <Resource name="jdbc/xxxx" auth="Container" user="xxxxxx" password="xxxxx" driverClass="com.mysql.jdbc

How to trace and prevent the deadlock appeared in c3po which is running in seperate processes?

主宰稳场 提交于 2019-12-05 03:53:16
I have a very simple computation which produces letter matrices finds probably all the words in the matrix. The letters in the word are adjacent cells. for (int i = 0; i < 500; i++) { System.out.println(i); Matrix matrix = new Matrix(4); matrix.scanWordsRandomly(9); matrix.printMatrix(); System.out.println(matrix.getSollSize()); matrix.write_to_db(); } Here is the persisting code. public void write_to_db() { Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Matrixtr onematrixtr = new Matrixtr(); onematrixtr.setDimension

how to return a connection in c3p0

耗尽温柔 提交于 2019-12-05 01:52:01
I am using c3p0 - ComboPooledDataSource. I am initializing once as below. private void init() { cpds = new ComboPooledDataSource(); cpds.setDriverClass(driverName); cpds.setJdbcUrl(url); cpds.setUser(userName); cpds.setPassword(pwd); } I am getting a connection from the pool as below public synchronized Connection getLocalConnection(String ipAddr) throws SQLException { return cpds.getConnection(); } But i am not sure whether its the right way to return the connection back to the pool when i finish executing a query. I guess the conn.close() just returns the connection back to the pool instead

JDBC+C3P0+DBCP 基本使用

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 01:23:17
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

jTDS socket hanging with C3P0 connection check (SQL Server 2008 R2)

淺唱寂寞╮ 提交于 2019-12-05 01:22:58
问题 Here is the environment: Java 5 Web application running in Tomcat 6.0.18 on Windows (not sure the version) Database: SQL Server 2008 R2 JDBC Driver: jTDS 1.2.5 Connection pool provider: C3P0 0.9.1.2 I am trying to debug a problem that a client is having. Basically every couple weeks, our web application locks up on their server, and they can't access it. A restart fixes the issue. Further investigation shows that the reason everything is locked up is that everything is waiting on the database

数据库连接池性能测试(hikariCP,druid,tomcat-jdbc,dbcp,c3p0)

蓝咒 提交于 2019-12-05 00:42:21
本文主要是对这hikariCP,druid,tomcat-jdbc,dbcp,c3p0几种连接池的详细的功能和性能测试对比,通过这次测试对目前主流的一些连接池做一个全面的对比,从而给业务系统一个最佳的推荐。 测试结论 性能方面 hikariCP>druid>tomcat-jdbc>dbcp>c3p0 。hikariCP的高性能得益于最大限度的避免锁竞争。 druid功能最为全面,sql拦截等功能,统计数据较为全面,具有良好的扩展性。 综合考虑到目前venus已经支持druid且hikariCP并未发现有太多大规模的生产实践的案例,后续将推荐使用druid并把codegen生成的代码默认连接池为druid。 可开启prepareStatement缓存,对性能会有大概10%的提升。 功能对比 功能 dbcp druid c3p0 tomcat-jdbc HikariCP 是否支持PSCache 是 是 是 否 否 监控 jmx jmx/log/http jmx,log jmx jmx 扩展性 弱 好 弱 弱 弱 sql拦截及解析 无 支持 无 无 无 代码 简单 中等 复杂 简单 简单 更新时间 2018.1.13 2018.1.14 2017.5.4 2018.1.14 特点 依赖于common-pool 阿里开源,功能全面 历史久远,代码逻辑复杂,且不易维护 优化力度大,功能简单

c3p0 how to shutdown all the database connections and re-open them when need?

巧了我就是萌 提交于 2019-12-05 00:18:13
问题 I have a TimerTask which runs one time (about 1 or 2 hours) each day. And at each running, it will create hundreds of threads to do some compute work for each table in MySQL database. and I use the c3p0 as the database source connection pool (each thread get the connection before computing and close the connection after computing). I set the connection pool configuration as below, cpDs = new ComboPooledDataSource(); cpDs.setMinPoolSize(10); cpDs.setMaxPoolSize(20); cpDs

JAVA--高级基础开发C3P0

故事扮演 提交于 2019-12-04 23:31:32
C3P0配置文件 <?xml version="1.0" encoding="UTF-8"?> <c3p0-config> <!--配置连接数据库的参数,作为默认配置--> <default-config> <!--设置连接参数--> <property name="driverClass">com.mysql.cj.jdbc.Driver</property> <property name="jdbcUrl">jdbc:mysql://localhost:3306/ab_wzy?serverTimezone=UTC</property>> <property name="user">root</property> <property name="password">root</property> <!--连接池参数设置--> <!--初始连接数--> <property name="initialPoolSize">5</property> <!--最大连接数--> <property name="maxPoolSize">10</property> <!--最大等待时间 毫秒为单位 --> <property name="checkoutTimeout">2000</property> <!--最大空闲时间--> <property name="maxIdleTime"

Hibernate连接数据库超时设置

天大地大妈咪最大 提交于 2019-12-04 22:15:36
com.MySQL.jdbc.CommunicationsException: The last packet successfully received from the server was58129 seconds ago.The last packet sent successfully to the server was 58129 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. 解决办法: 如果连接闲置8小时 (8小时内没有进行数据库操作), mysql就会自动断开连接, 要重启tomcat. 不用hibernate的话, connection url加参数: