dbcp配置选项


 

testOnBorrow默认为true, 要设置为false.  若设置validationQuery则对性能影响比较大.

testWhileIdle默认为false,设置为true.并设置validationQuery

maxIdle最好设置为与maxActive一样。

initialSize与minIdle按业务要求配置,一般都要配置。

timeBetweenEvictionRunsMillis默认为-1.设置一定数值300000

numTestsPerEvictionRun默认是3, 这个值要调大点maxActive的一半较好。 

 

以下apache dbcp的配置项

 

Parameters


ParameterDescription
usernameThe connection username to be passed to our JDBC driver to establish a connection.
passwordThe connection password to be passed to our JDBC driver to establish a connection.
urlThe connection URL to be passed to our JDBC driver to establish a connection.
driverClassNameThe fully qualified Java class name of the JDBC driver to be used.
connectionPropertiesThe connection properties that will be sent to our JDBC driver when establishing new connections. 
Format of the string must be [propertyName=property;]* 
NOTE - The "user" and "password" properties will be passed explicitly, so they do not need to be included here.

ParameterDefaultDescription
defaultAutoCommittrueThe default auto-commit state of connections created by this pool.
defaultReadOnlydriver defaultThe default read-only state of connections created by this pool. If not set then the setReadOnly method will not be called. (Some drivers don't support read only mode, ex: Informix)
defaultTransactionIsolationdriver defaultThe default TransactionIsolation state of connections created by this pool. One of the following: (see javadoc)
  • NONE
  • READ_COMMITTED
  • READ_UNCOMMITTED
  • REPEATABLE_READ
  • SERIALIZABLE
defaultCatalogThe default catalog of connections created by this pool.

ParameterDefaultDescription
initialSize0The initial number of connections that are created when the pool is started. 
Since: 1.2
maxActive8The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit.
maxIdle8The maximum number of connections that can remain idle in the pool, without extra ones being released, or negative for no limit.
minIdle0The minimum number of connections that can remain idle in the pool, without extra ones being created, or zero to create none.
maxWaitindefinitelyThe maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or -1 to wait indefinitely.

NOTE: If maxIdle is set too low on heavily loaded systems it is possible you will see connections being closed and almost immediately new connections being opened. This is a result of the active threads momentarily closing connections faster than they are opening them, causing the number of idle connections to rise above maxIdle. The best value for maxIdle for heavily loaded system will vary but the default is a good starting point.


ParameterDefaultDescription
validationQueryThe SQL query that will be used to validate connections from this pool before returning them to the caller. If specified, this query MUST be an SQL SELECT statement that returns at least one row.
testOnBorrowtrueThe indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another.
NOTE - for a true value to have any effect, thevalidationQuery parameter must be set to a non-null string.
testOnReturnfalseThe indication of whether objects will be validated before being returned to the pool. 
NOTE - for a true value to have any effect, thevalidationQuery parameter must be set to a non-null string.
testWhileIdlefalseThe indication of whether objects will be validated by the idle object evictor (if any). If an object fails to validate, it will be dropped from the pool. 
NOTE - for a true value to have any effect, thevalidationQuery parameter must be set to a non-null string.
timeBetweenEvictionRunsMillis-1The number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive, no idle object evictor thread will be run.
numTestsPerEvictionRun3The number of objects to examine during each run of the idle object evictor thread (if any).
minEvictableIdleTimeMillis1000 * 60 * 30The minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor (if any).
connectionInitSqls 
NOTE: Versions 1.3 and 1.4 of DBCP incorrectly use "initConnectionSqls" as the name of this property for JNDI object factory configuration. Until 1.3.1/1.4.1 are released, "initConnectionSqls" must be used as the name for this property when using BasicDataSoureFactory to create BasicDataSource instances via JNDI.
nullA Collection of SQL statements that will be used to initialize physical connections when they are first created. These statements are executed only once - when the configured connection factory creates the connection.

ParameterDefaultDescription
poolPreparedStatementsfalseEnable prepared statement pooling for this pool.
maxOpenPreparedStatementsunlimitedThe maximum number of open statements that can be allocated from the statement pool at the same time, or zero for no limit.

 This component has also the ability to pool PreparedStatements. When enabled a statement pool will be created for each Connection and PreparedStatements created by one of the following methods will be pooled:

  • public PreparedStatement prepareStatement(String sql)
  • public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)

 

NOTE - Make sure your connection has some resources left for the other statements. Pooling PreparedStatements may keep their cursors open in the database, causing a connection to run out of cursors, especially if maxOpenPreparedStatements is left at the default (unlimited) and an application opens a large number of different PreparedStatements per connection. To avoid this problem, maxOpenPreparedStatements should be set to a value less than the maximum number of cursors that can be open on a Connection.


ParameterDefaultDescription
accessToUnderlyingConnectionAllowedfalseControls if the PoolGuard allows access to the underlying connection.

When allowed you can access the underlying connection using the following construct:

    Connection conn = ds.getConnection();
    Connection dconn = ((DelegatingConnection) conn).getInnermostDelegate();
    ...
    conn.close()

 Default is false, it is a potential dangerous operation and misbehaving programs can do harmfull things. (closing the underlying or continue using it when the guarded connection is already closed) Be carefull and only use when you need direct access to driver specific extentions.

NOTE: Do not close the underlying connection, only the original one.


ParameterDefaultDescription
removeAbandonedfalseFlag to remove abandoned connections if they exceed the removeAbandonedTimout.
If set to true a connection is considered abandoned and eligible for removal if it has been idle longer than the removeAbandonedTimeout. Setting this to true can recover db connections from poorly written applications which fail to close a connection.
removeAbandonedTimeout300Timeout in seconds before an abandoned connection can be removed.
logAbandonedfalseFlag to log stack traces for application code which abandoned a Statement or Connection.
Logging of abandoned Statements and Connections adds overhead for every Connection open or new Statement because a stack trace has to be generated.

 If you have enabled "removeAbandoned" then it is possible that a connection is reclaimed by the pool because it is considered to be abandoned. This mechanism is triggered when (getNumIdle() < 2) and (getNumActive() > getMaxActive() - 3)

 For example maxActive=20 and 18 active connections and 1 idle connection would trigger the "removeAbandoned". But only the active connections that aren't used for more then "removeAbandonedTimeout" seconds are removed, default (300 sec). Traversing a resultset doesn't count as being used.

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值