`
fan2012
  • 浏览: 68466 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

HowTo configure the C3P0 connection pool

阅读更多
Configuration
Here is a sample of C3P0 configuration. This is an extract of hibernate.cfg.xml:
<!-- configuration pool via c3p0--> 
<property name="c3p0.acquire_increment">1</property> 
<property name="c3p0.idle_test_period">100</property> <!-- seconds --> 
<property name="c3p0.max_size">100</property> 
<property name="c3p0.max_statements">0</property> 
<property name="c3p0.min_size">10</property> 
<property name="c3p0.timeout">100</property> <!-- seconds --> 
<!-- DEPRECATED very expensive property name="c3p0.validate>--> 


You also can set extra c3p0 properties using c3p0.properties. Put this file in the classpath (WEB-INF/classes for example), but be careful, the previous values will be overridden by Hibernate whether set or not (see below for more details). For more information on C3P0 configuration, please have a look at http://sourceforge.net/projects/c3p0 and unzip the download, there is a doc folder where you'll find everything you need.

For more on hibernate/c3p0 issues, see c3p0's docs at http://www.mchange.com/projects/c3p0/index.html#appendix_d

#

Parameters
c3p0 is very tunable, and offers a somewhat bewildering array of configuration parameters. For the complete list, see http://www.mchange.com/projects/c3p0/index.html#appendix_a

Here are a subset of the most important features:


initialPoolSize C3P0 default: 3


minPoolSize Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 1


maxPoolSize Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 100


idleTestPeriod Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 0

If this is a number greater than 0, c3p0 will test all idle, pooled but unchecked-out connections, every this number of seconds.


timeout Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 0

The seconds a Connection can remain pooled but unused before being discarded. Zero means idle connections never expire.


maxStatements Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 0

The size of c3p0's PreparedStatement cache. Zero means statement caching is turned off.


propertyCycle Must be set in c3p0.properties, C3P0 default: 300

Maximum time in seconds before user configuration constraints are enforced. c3p0 enforces configuration constraints continually, and ignores this parameter. It is included for JDBC3 completeness.


acquireIncrement Must be set in hibernate.cfg.xml (or hibernate.properties), Hibernate default: 1

Determines how many connections at a time c3p0 will try to acquire when the pool is exhausted.


testConnectionOnCheckout Must be set in c3p0.properties, C3P0 default: false

Don't use it, this feature is very expensive. If set to true, an operation will be performed at every connection checkout to verify that the connection is valid. A better choice is to verify connections periodically using c3p0.idleConnectionTestPeriod.


autoCommitOnClose Must be set in c3p0.properties, C3P0 default: false

The JDBC spec is unfortunately silent on what should happen to unresolved, pending transactions on Connection close. C3P0's default policy is to rollback any uncommitted, pending work. (I think this is absolutely, undeniably the right policy, but there is no consensus among JDBC driver vendors.) Setting autoCommitOnClose to true causes uncommitted pending work to be committed, rather than rolled back on Connection close. [Note: Since the spec is absurdly unclear on this question, application authors who wish to avoid bugs and inconsistent behavior should ensure that all transactions are explicitly either committed or rolled-back before close is called.]


forceIgnoreUnresolvedTransactions Must be set in c3p0.properties, C3P0 default: false

Strongly disrecommended. Setting this to true may lead to subtle and bizarre bugs. This is a terrible setting, leave it alone unless absolutely necessary. It is here to work around broken databases / JDBC drivers that do not properly support transactions, but that allow Connections' autoCommit flags to be set to false regardless. If you are using a database that supports transactions "partially" (this is oxymoronic, as the whole point of transactions is to perform operations reliably and completely, but nevertheless, such databases exist), if you feel comfortable ignoring the fact that Connections with autoCommit == false may be in the middle of transactions and may hold locks and other resources, you may turn off c3p0's wise default behavior, which is to protect itself, as well as the usability and consistency of the database, by either rolling back (default) or committing (see c3p0.autoCommitOnClose above) unresolved transactions. This should only be set to true when you are sure you are using a database that allows Connections' autoCommit flag to go to false, but that it offers no other meaningful support of transactions. Otherwise setting this to true is just a bad idea.


numHelperThreads Must be set in c3p0.properties, C3P0 default: 3

c3p0 is very asynchronous. Slow JDBC operations are generally performed by helper threads that don't hold contended locks. Spreading these operations over multiple threads can significantly improve performance by allowing multiple operations to be performed simultaneously.


factoryClassLocation Must be set in c3p0.properties, C3P0 default: null

DataSources that will be bound by JNDI and use that API's Referenceable interface to store themselves may specify a URL from which the class capable of dereferencing a them may be loaded. If (as is usually the case) the c3p0 libraries will be locally available to the JNDI service, leave this set to null.

Regards,

Anthony

(see http://forum.hibernate.org/viewtopic.php?t=934779 for more details)


--------------------------------------------------------------------------------

If you want to get rid of the C3P0 status that is printed, by default, when hibernate starts, you need to recompile C3P0 sources after changing com.mchange.v2.c3p0.Debug.DEBUG to false.

This is a public static final field that cannot be changed by configuration files.

Hibernate's C3P0ConnectionProvider explicitly sets 7 c3p0 configuration properties, based on your hibernate configuration, overriding any configuration you may have set in a c3p0.properties file. If you are using Hibernate's C3P0ConnectionProvider you must set the following properties in your hibernate configuration, using hibernate-specific configuration keys. All other properties must be defined as usual in a c3p0.properties file. This is confusing, and will hopefully be simplified some time in the future, but for now...

The following properties must be set in your hibernate configuration:

c3p0-native property name hibernate configuration key 
c3p0.acquireIncrement hibernate.c3p0.acquire_increment 
c3p0.idleConnectionTestPeriod hibernate.c3p0.idle_test_period 
c3p0.initialPoolSize not available -- uses minimum size 
c3p0.maxIdleTime hibernate.c3p0.timeout 
c3p0.maxPoolSize hibernate.c3p0.max_size 
c3p0.maxStatements hibernate.c3p0.max_statements 
c3p0.minPoolSize hibernate.c3p0.min_size 
c3p0.testConnectionsOnCheckout  hibernate.c3p0.validate hibernate 2.x only! 

Remember -- these, and only these, properties must be defined in your hibernate configuration, or else they will be set to hibernate-specified defaults. All other configuration properties that you wish to set should be defined in a c3p0.properties file. (See "Overriding c3p0 defaults via c3p0.properties".)

分享到:
评论

相关推荐

    How to configure DCM UDS with the DEXT Editor.pdf

    How to configure DCM UDS with the DEXT Editor.pdf

    hibernate c3p0实例源码

    在Java的持久层框架...&lt;property name="connection.provider_class"&gt;org.hibernate.connection.C3P0ConnectionProvider &lt;property name="hibernate.c3p0.min_size"&gt;5 &lt;property name="hibernate.c3p0.max_size"&gt;20 ...

    c3p0数据库连接池所需jar包c3p0-oracle-thin-extras-0.9.1.2.rar

    c3p0数据库连接池所需jar包,c3p0数据库连接池所需jar包c3p0-oracle-thin-extras-0.9.1.2、c3p0-0.9.1.2.jar、c3p0-0.9.1.2-jdk1.3.jar  1、首先在项目下创建一个文件夹,保存我们的jar包。在项目名上右击,依次...

    Configure RTX v5.pdf

    Memory Pool Configuration provides several parameters to configure the Memory Pool functions. Message Queue Configuration provides several parameters to configure the Message Queue functions. Event ...

    hibernate3.0+c3p0 重新自动连接

    config.setProperty("hibernate.connection.datasource", "org.hibernate.connection.c3p0.DriverManagerDataSource"); ServiceRegistry registry = new StandardServiceRegistryBuilder().applySettings(config....

    在eclipse下的c3p0实例

    return C3P0Config.cpds.getConnection(); } public static void closeConnection(Connection conn) { if (conn != null) { try { conn.close(); } catch (Exception e) {} } } // 其他数据库操作方法.....

    How to configure ODBC DSN to access local DB2 for Windows

    This article introduces how to configure ODBC DSN in Server to access local DB2 for windows in detail. Then I give a sample how to access local DB2 database with ODBC by DB Query Analyzer expediently.

    How to Configure the Watchdog BSW Stack's Supervision.pdf

    这份文档是一份全面的技术指南,用于指导用户如何在RTA-BSW中配置看门狗(Watchdog)的监控功能。看门狗是一种安全机制,用于确保汽车电子控制单元(ECU)中软件组件的正确运行。文档涵盖了从基础概念到具体配置步骤...

    How to configure ODBC DSN in Client to access DB2 for Windows.

    This article introduces how to configure ODBC DSN in Client to access remote DB2 for windows in detail. Then I give a sample how to access remote DB2 database with ODBC by DB Query Analyzer ...

    hibernate使用c3p0连接池的资料

    &lt;property name="connection.provider_class"&gt;org.hibernate.connection.C3P0ConnectionProvider &lt;property name="c3p0.acquire_increment"&gt;2 &lt;property name="c3p0.idle_test_period"&gt;200 &lt;property name="c3p0...

    How to Configure Odoo 13 on Pycharm Ubuntu 18(1).mp4

    How to Configure Odoo 13 on Pycharm Ubuntu 18 ubuntu18下安装ODOO13 pycharm配置ODOO13开发环境

    Hibernate结合C3P0的小例子

    C3P0是Com审议Connection Pooling的缩写,它提供了一个灵活且强大的数据库连接池实现。C3P0的主要功能包括自动检测并修复失效的连接、支持多线程环境下的并发连接以及通过配置参数优化数据库连接的创建和回收。 接...

    HibernateC3P0 数据库连接池架包.rar

    3. 初始化C3P0连接池:通过`hibernate.connection.provider_class`属性指定为`org.hibernate.connection.C3P0ConnectionProvider`。 四、使用HibernateC3P0 在Java代码中,我们可以通过SessionFactory对象来获取和...

    AUTOSAR XCP详细配置流程 How to configure XCP

    这份应用说明文档提供了在 RTA-CAR 9.1.0 VRTA Starter Kit 上配置 XCP(测量和校准协议)的详细步骤。XCP 配置涉及对 DBC 和 DBF 文件的更新,ECU 配置的更新,XCP BSW 模块的配置,BswM 动作列表的初始化,SWC 的...

    HIbernate4.3.6整合c3p0所需jar

    Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.connection.C3P0ConnectionProvider] as strategy [org.hibernate.engine.jdbc....

    VMware vSphere 6.5 Cookbook 3rd Edition.pdf

    Chapter 1, Upgrading to vSphere 6.5, will teach you how to upgrade your existing environment to the vSphere 6.5, and you will also learn how to migrate vCenter running onWindows to appliance. ...

    modem-setting.zip_How To Network

    how to configure or add a new modem to a workstation network, so we can use 2 line of connection

    英文原版-CentOS Bible 1st Edition

    This is one of the first, if not the first comprehensive guide to the CentOS Linux operating system.First find out how to install and configure CentOS. From there, you’ll cover a wealth of Linux and ...

    两天成为Oracle_DBA(PDF版)

    describes how to configure additional databases, and how to upgrade and older version of a database to the current version. Chapter 3, "Getting Started with Oracle Enterprise Manager" This chapter ...

    Raspberry Pi Robotics Essentials [Richard Grimmett]

    Chapter 1, Configuring and ...Chapter 7, Accessing Your Biped Remotely, covers the basics of how to configure the Raspberry Pi as a wireless access point so that you can control your biped remotely.

Global site tag (gtag.js) - Google Analytics