spring oracle c3p0,Spring 结合Hibernate 配置 C3P0 连接池

applicationContext.xml 文件:

class="com.mchange.v2.c3p0.ComboPooledDataSource"

destroy-method="close">

com.mysql.jdbc.Driver

jdbc:mysql://ip地址:3306/数据库名字?useUnicode=true&characterEncoding=utf-8

root

root

5

30

10

60

5

0

60

30

true

false

Default: 3

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

Default: 30

Defines how many times c3p0 will try to acquire a new Connection from the database before giving up. If this value is less than or equal to zero, c3p0 will keep trying to fetch a Connection indefinitely. [See

Default: 1000

Milliseconds, time c3p0 will wait between acquire attempts. [See

Default: false

The JDBC spec is unforgivably 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.) SettingautoCommitOnCloseto 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.] [See

Default: null

If provided, c3p0 will create an empty table of the specified name, and use queries against that table to test the Connection. IfautomaticTestTableis provided, c3p0 will generate its own test query, therefore anypreferredTestQueryset will be ignored. You should not work with the named table after c3p0 creates it; it should be strictly for c3p0's use in testing your Connection. (If you define your own ConnectionTester, it must implement the

Default: false

If true, a pooled DataSource will declare itself broken and be permanently closed if a Connection cannot be obtained from the database after makingacquireRetryAttemptsto acquire one. If false, failure to obtain a Connection will cause all Threads waiting for the pool to acquire a Connection to throw an Exception, but the DataSource will remain valid, and will attempt to acquire again following a call togetConnection(). [See

Default: 0

The number of milliseconds a client calling getConnection() will wait for a Connection to be checked-in or acquired when the pool is exhausted. Zero means wait indefinitely. Setting any positive value will cause the getConnection() call to time-out and break with anSQLExceptionafter the specified number of milliseconds.

Default: null

The fully qualified class-name of an implememtation of theConnectionCustomizer interface, which users can implement to set up Connections when they are acquired from the database, or on check-out, and potentially to clean things up on check-in and Connection destruction. If standard Connection properties (holdability, readOnly, or transactionIsolation) are set in the ConnectionCustomizer's onAcquire() method, these will override the Connection default values.

Default: com.mchange.v2.c3p0.impl.DefaultConnectionTester

The fully qualified class-name of an implememtation of theConnectionTester interface, or QueryConnectionTester if you would like instances to have access to a user-configuredpreferredTestQuery. This can be used to customize how c3p0 DataSources test Connections, but with the introduction ofautomaticTestTableandpreferredTestQueryconfiguration parameters, "rolling your own" should be overkill for most users. [See "Configuring Connection Testing"]

Default: false

If true, and ifis set to a positive value, then the pool will capture the stack trace (via an Exception) of all Connection checkouts, and the stack traces will be printed when unreturned checked-out Connections timeout. This is intended to debug applications with Connection leaks, that is applications that occasionally fail to return Connections, leading to pool growth, and eventually exhaustion (when the pool hitsmaxPoolSizewith all Connections checked-out and lost). This parameter should only be set while debugging, as capturing the stack trace will slow down every Connection check-out.

Does Not Support Per-User Overrides.

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 as null.

Does Not Support Per-User Overrides.

Default: false

Strongly disrecommended. Setting this totruemay lead to subtle and bizarre bugs.This is a terrible setting, leave it alone unless absolutely necessary. It is here to workaround broken databases / JDBC drivers that do not properly support transactions, but that allow Connections'autoCommitflags to go 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 nonetheless such databases are out there), if you feel comfortable ignoring the fact that Connections withautoCommit == falsemay 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 (seec3p0.autoCommitOnCloseabove) 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 offers no other meaningful support of transactions. Otherwise setting this to true is just a bad idea. [See

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. [See

Default: 3

Number of Connections a pool will try to acquire upon startup. Should be betweenminPoolSizeandmaxPoolSize. [See

Default: 0

Seconds before c3p0's thread pool will try to interrupt an apparently hung task. Rarely useful. Many of c3p0's functions are not performed by client threads, but asynchronously by an internal thread pool. c3p0's asynchrony enhances client performance directly, and minimizes the length of time that critical locks are held by ensuring that slow jdbc operations are performed in non-lock-holding threads. If, however, some of these tasks "hang", that is they neither succeed nor fail with an Exception for a prolonged period of time, c3p0's thread pool can become exhausted and administrative tasks backed up. If the tasks are simply slow, the best way to resolve the problem is to increase the number of threads, vianumHelperThreads. But if tasks sometimes hang indefinitely, you can use this parameter to force a call to the task thread'sinterrupt()method if a task exceeds a set time limit. [c3p0 will eventually recover from hung tasks anyway by signalling an "APPARENT DEADLOCK" (you'll see it as a warning in the logs), replacing the thread pool task threads, and interrupt()ing the original threads. But letting the pool go into APPARENT DEADLOCK and then recover means that for some periods, c3p0's performance will be impaired. So if you're seeing these messages, increasing numHelperThreads and settingmaxAdministrativeTaskTimemight help.maxAdministrativeTaskTimeshould be large enough that any resonable attempt to acquire a Connection from the database, to test a Connection, or two destroy a Connection, would be expected to succeed or fail within the time set. Zero (the default) means tasks are never interrupted, which is the best and safest policy under most circumstances. If tasks are just slow, allocate more threads. If tasks are hanging forever, try to figure out why, and maybe settingmaxAdministrativeTaskTimecan help in the meantime.

Does Not Support Per-User Overrides.

Default: 0

Seconds, effectively a time to live. A Connection older thanmaxConnectionAgewill be destroyed and purged from the pool. This differs frommaxIdleTimein that it refers to absolute age. Even a Connection which has not been much idle will be purged from the pool if it exceedsmaxConnectionAge. Zero means no maximum absolute age is enforced.

Default: 0

Seconds a Connection can remain pooled but unused before being discarded. Zero means idle connections never expire. [See

Default: 0

Number of seconds that Connections in excess ofminPoolSizeshould be permitted to remain idle in the pool before being culled. Intended for applications that wish to aggressively minimize the number of open Connections, shrinking the pool back towards minPoolSize if, following a spike, the load level diminishes and Connections acquired are no longer needed. IfmaxIdleTimeis set,maxIdleTimeExcessConnectionsshould be smaller if the parameter is to have any effect. Zero means no enforcement, excess Connections are not idled out.

Default: 15

Maximum number of Connections a pool will maintain at any given time. [See

Default: 0

The size of c3p0's global PreparedStatement cache. If bothmaxStatementsandmaxStatementsPerConnectionare zero, statement caching will not be enabled. IfmaxStatementsis zero butmaxStatementsPerConnectionis a non-zero value, statement caching will be enabled, but no global limit will be enforced, only the per-connection maximum.maxStatementscontrols the total number of Statements cached, for all Connections. If set, it should be a fairly large number, as each pooled Connection requires its own, distinct flock of cached statements. As a guide, consider how many distinct PreparedStatements are used frequently in your application, and multiply that number bymaxPoolSizeto arrive at an appropriate value. ThoughmaxStatementsis the JDBC standard parameter for controlling statement caching, users may find c3p0's alternativemaxStatementsPerConnectionmore intuitive to use. [See

Default: 0

The number of PreparedStatements c3p0 will cache for a single pooled Connection. If bothmaxStatementsandmaxStatementsPerConnectionare zero, statement caching will not be enabled. IfmaxStatementsPerConnectionis zero butmaxStatementsis a non-zero value, statement caching will be enabled, and a global limit enforced, but otherwise no limit will be set on the number of cached statements for a single Connection. If set, maxStatementsPerConnection should be set to about the number distinct PreparedStatements that are used frequently in your application, plus two or three extra so infrequently statements don't force the more common cached statements to be culled. ThoughmaxStatementsis the JDBC standard parameter for controlling statement caching, users may findmaxStatementsPerConnectionmore intuitive to use. [See

Default: 3

Minimum number of Connections a pool will maintain at any given time. [See

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.

Does Not Support Per-User Overrides.

Default: null

Forces the username that should by PooledDataSources when a user calls the default getConnection() method. This is primarily useful when applications are pooling Connections from a non-c3p0 unpooled DataSource. Applications that useComboPooledDataSource, or that wrap any c3p0-implemented unpooled DataSource can use the simpleuser property.

Does Not Support Per-User Overrides.

Default: null

Forces the password that should by PooledDataSources when a user calls the default getConnection() method. This is primarily useful when applications are pooling Connections from a non-c3p0 unpooled DataSource. Applications that useComboPooledDataSource, or that wrap any c3p0-implemented unpooled DataSource can use the simplepassword property.

Does Not Support Per-User Overrides.

Default: null

For applications usingComboPooledDataSourceor any c3p0-implemented unpooled DataSources —DriverManagerDataSourceor the DataSource returned byDataSources.unpooledDataSource( ... )— defines the password that will be used for the DataSource's defaultgetConnection()method. (See also

Does Not Support Per-User Overrides.

Default: null

Defines the query that will be executed for all connection tests, if the default ConnectionTester (or some other implementation ofpreferredTestQuerythat will execute quickly in your database may dramatically speed up Connection tests. (If nopreferredTestQueryis set, the default ConnectionTester executes agetTables()call on the Connection's DatabaseMetaData. Depending on your database, this may execute more slowly than a "normal" database query.) NOTE: The table against which yourpreferredTestQuerywill be run must exist in the database schema prior to your initialization of your DataSource. If your application defines its own schema, tryautomaticTestTableinstead.

Default: 0

Maximum time in seconds before user configuration constraints are enforced. Determines how frequentlymaxConnectionAge,maxIdleTime,maxIdleTimeExcessConnections,unreturnedConnectionTimeoutare enforced. c3p0 periodically checks the age of Connections to see whether they've timed out. This parameter determines the period. Zero means automatic: A suitable period will be determined by c3p0. [You can callgetEffectivePropertyCycle...()methods on a c3p0PooledDataSource to find the period automatically chosen.]

Default: false

If true, an operation will be performed asynchronously at every connection checkin to verify that the connection is valid. Use in combination withidleConnectionTestPeriodfor quite reliable, always asynchronous Connection testing. Also, setting anautomaticTestTableorpreferredTestQuerywill usually speed up all connection tests. [See

Default: false

Use only if necessary. Expensive.If true, an operation will be performed at every connection checkout to verify that the connection is valid. Better choice: verify connections periodically usingidleConnectionTestPeriod. Also, setting anautomaticTestTableorpreferredTestQuerywill usually speed up all connection tests. [See

Default: 0

Seconds. If set, if an application checks out but then fails to check-in [i.e. close()] a Connection within the specified period of time, the pool will unceremoniously destroy() the Connection. This permits applications with occasional Connection leaks to survive, rather than eventually exhausting the Connection pool. And that's a shame. Zero means no timeout, applications are expected to close() their own Connections. Obviously, if a non-zero value is set, it should be to a value longer than any Connection should reasonably be checked-out. Otherwise, the pool will occasionally kill Connections in active use, which is bad. This is basically a bad idea, but it's a commonly requested feature. Fix your $%!@% applications so they don't leak Connections! Use this temporarily in combination withdebugUnreturnedConnectionStackTracesto figure out where Connections are being checked-out that don't make it back into the pool!

Default: null

For applications usingComboPooledDataSourceor any c3p0-implemented unpooled DataSources —DriverManagerDataSourceor the DataSource returned byDataSources.unpooledDataSource()— defines the username that will be used for the DataSource's defaultgetConnection()method. (See also

Does Not Support Per-User Overrides.

Default: false

c3p0 originally used reflective dynamic proxies for implementations of Connections and other JDBC interfaces. As of c3p0-0.8.5, non-reflective, code-generated implementations are used instead. As this was a major change, and the old codebase had been extensively used and tested, this parameter was added to allow users to revert of they had problems. The new, non-reflexive implementation is faster, and has now been widely deployed and tested, so it is unlikely that this parameter will be useful. Both the old reflective and newer non-reflective codebases are being maintained, but support for the older codebase may (or may not) be dropped in the future.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值