From: fhanik The JDBC Connection Pool So why do we need a new connection pool? Here are a few of the reasons:
+ org.apache.tomcat.jdbc.pool
+ is a replacement or an alternative to the commons-dbcp
+ connection pool.
+
+
Features added over other connection pool implementations +
To provide a very simple switch to and from commons-dbcp and tomcat-jdbc-pool, + Most attributes are the same and have the same meaning.
+ + +factory is required, and the value should be org.apache.tomcat.jdbc.poo.DataSourceFactory
Type should always be javax.sql.DataSource
These attributes are shared between commons-dbcp and tomcat-jdbc-pool, in some cases default values are different.
+(boolean) The default auto-commit state of connections created by this pool. If not set, default is JDBC driver default (If not set then the setAutoCommit method will not be called.)
+(boolean) The 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)
+(String) The default TransactionIsolation state of connections created by this pool. One of the following: (see javadoc )
+ * NONE
+ * READ_COMMITTED
+ * READ_UNCOMMITTED
+ * REPEATABLE_READ
+ * SERIALIZABLE
+ If not set, the method will not be called and it defaults to the JDBC driver.
+
(String) The default catalog of connections created by this pool.
+(String) The fully qualified Java class name of the JDBC driver to be used. The driver has to be accessible + from the same classloader as tomcat-jdbc.jar +
+(String) The connection username to be passed to our JDBC driver to establish a connection.
+ Note, at this point, DataSource.getConnection(username,password) is not using the credentials passed into the method.
+
(String) The connection password to be passed to our JDBC driver to establish a connection.
+ Note, at this point, DataSource.getConnection(username,password) is not using the credentials passed into the method.
+
(int) The maximum number of active connections that can be allocated from this pool at the same time.
+ The default value is 100
(int) The maximum number of connections that should be kept in the pool at all times.
+ Default value is maxActive:100
+ Idle connections are checked periodically (if enabled) and
+ connections that been idle for longer than minEvictableIdleTimeMillis
+ will be released. (also see testWhileIdle)
+ (int) The minimum number of established connections that should be kept in the pool at all times.
+ The connection pool can shrink below this number if validation queries fail.
+ Default value is derived from initialSize:10 (also see testWhileIdle)
+
(int)The initial number of connections that are created when the pool is started.
+ Default value is 10
(long) The 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.
+ Default value is 30000 (30 seconds)
(boolean) The 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, the validationQuery parameter must be set to a non-null string.
+ Default value is false
+
(boolean) The indication of whether objects will be validated before being returned to the pool.
+ NOTE - for a true value to have any effect, the validationQuery parameter must be set to a non-null string.
+ The default value is false.
+
(boolean) The 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, the validationQuery parameter must be set to a non-null string.
+ The default value is false and this property has to be set in order for the
+ pool cleaner/test thread is to run (also see timeBetweenEvictionRunsMillis)
+
(String) The SQL query that will be used to validate connections from this pool before returning them to the caller.
+ If specified, this query does not have to return any data, it just can't throw a SQLException.
+ The default value is null.
+ Example values are SELECT 1(mysql), select 1 from dual(oracle), SELECT 1(MS Sql Server)
+
(long) The number of milliseconds to sleep between runs of the idle connection validation/cleaner thread.
+ This value should not be set under 1 second. It dictates how often we check for idle, abandoned connections, and how often
+ we validate idle connections.
+ The default value is 5000 (5 seconds).
(int) Property not used in tomcat-jdbc-pool.
+(long) The minimum amount of time an object may sit idle in the pool before it is eligable for eviction.
+ The default value is 60000 (60 seconds).
(boolean) Property not used. Access can be achieved by calling unwrap on the pooled connection.
+ see javax.sql.DataSource interface, or call getConnection through reflection.
(boolean) Flag 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 in use
+ longer than the removeAbandonedTimeout Setting this to true can recover db connections from
+ applications that fail to close a connection. See also logAbandoned
+ The default value is false.
(long) Timeout in seconds before an abandoned(in use) connection can be removed.
+ The default value is 60 (60 seconds). The value should be set to the longest running query your applications
+ might have.
(boolean) Flag to log stack traces for application code which abandoned a Connection.
+ Logging of abandoned Connections adds overhead for every Connection borrow because a stack trace has to be generated.
+ The default value is false.
(String) The 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.
+ The default value is null.
(boolean) Property not used. The default value is false.
(int) Property not used. The default value is false.
(String) A custom query to be run when a connection is first created.
+ The default value is null.
(String) A semicolon separated list of classnames extending org.apache.tomcat.jdbc.pool.JdbcInterceptor class.
+ These interceptors will be inserted as an interceptor into the chain of operations on a java.sql.Connection object.
+ The default value is null.
(long) avoid excess validation, only run validation at most at this frequency - time in milliseconds.
+ If a connection is due for validation, but has been validated previously within this interval, it will not be validated again.
+ The default value is 30000 (30 seconds).
(boolean) Register the pool with JMX or not.
+ The default value is true.
The JDBC Connection Pool org.apache.tomcat.jdbc.pool
- is a replacement or an alternative to the commons-dbcp
- connection pool.
So why do we need a new connection pool?
- -Here are a few of the reasons: -
Features added over other connection pool implementations -
To provide a very simple switch to and from commons-dbcp and tomcat-jdbc-pool, - Most attributes are the same and have the same meaning.
- - -factory is required, and the value should be org.apache.tomcat.jdbc.poo.DataSourceFactory
Type should always be javax.sql.DataSource
These attributes are shared between commons-dbcp and tomcat-jdbc-pool, in some cases default values are different.
-(boolean) The default auto-commit state of connections created by this pool. If not set, default is JDBC driver default (If not set then the setAutoCommit method will not be called.)
-(boolean) The 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)
-(String) The default TransactionIsolation state of connections created by this pool. One of the following: (see javadoc )
- * NONE
- * READ_COMMITTED
- * READ_UNCOMMITTED
- * REPEATABLE_READ
- * SERIALIZABLE
- If not set, the method will not be called and it defaults to the JDBC driver.
-
(String) The default catalog of connections created by this pool.
-(String) The fully qualified Java class name of the JDBC driver to be used. The driver has to be accessible - from the same classloader as tomcat-jdbc.jar -
-(String) The connection username to be passed to our JDBC driver to establish a connection.
- Note, at this point, DataSource.getConnection(username,password) is not using the credentials passed into the method.
-
(String) The connection password to be passed to our JDBC driver to establish a connection.
- Note, at this point, DataSource.getConnection(username,password) is not using the credentials passed into the method.
-
(int) The maximum number of active connections that can be allocated from this pool at the same time.
- The default value is 100
(int) The maximum number of connections that should be kept in the pool at all times.
- Default value is maxActive:100
- Idle connections are checked periodically (if enabled) and
- connections that been idle for longer than minEvictableIdleTimeMillis
- will be released. (also see testWhileIdle)
- (int) The minimum number of established connections that should be kept in the pool at all times.
- The connection pool can shrink below this number if validation queries fail.
- Default value is derived from initialSize:10 (also see testWhileIdle)
-
(int)The initial number of connections that are created when the pool is started.
- Default value is 10
(long) The 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.
- Default value is 30000 (30 seconds)
(boolean) The 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, the validationQuery parameter must be set to a non-null string.
- Default value is false
-
(boolean) The indication of whether objects will be validated before being returned to the pool.
- NOTE - for a true value to have any effect, the validationQuery parameter must be set to a non-null string.
- The default value is false.
-
(boolean) The 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, the validationQuery parameter must be set to a non-null string.
- The default value is false and this property has to be set in order for the
- pool cleaner/test thread is to run (also see timeBetweenEvictionRunsMillis)
-
(String) The SQL query that will be used to validate connections from this pool before returning them to the caller.
- If specified, this query does not have to return any data, it just can't throw a SQLException.
- The default value is null.
- Example values are SELECT 1(mysql), select 1 from dual(oracle), SELECT 1(MS Sql Server)
-
(long) The number of milliseconds to sleep between runs of the idle connection validation/cleaner thread.
- This value should not be set under 1 second. It dictates how often we check for idle, abandoned connections, and how often
- we validate idle connections.
- The default value is 5000 (5 seconds).
(int) Property not used in tomcat-jdbc-pool.
-(long) The minimum amount of time an object may sit idle in the pool before it is eligable for eviction.
- The default value is 60000 (60 seconds).
(boolean) Property not used. Access can be achieved by calling unwrap on the pooled connection.
- see javax.sql.DataSource interface, or call getConnection through reflection.
(boolean) Flag 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 in use
- longer than the removeAbandonedTimeout Setting this to true can recover db connections from
- applications that fail to close a connection. See also logAbandoned
- The default value is false.
(long) Timeout in seconds before an abandoned(in use) connection can be removed.
- The default value is 60 (60 seconds). The value should be set to the longest running query your applications
- might have.
(boolean) Flag to log stack traces for application code which abandoned a Connection.
- Logging of abandoned Connections adds overhead for every Connection borrow because a stack trace has to be generated.
- The default value is false.
(String) The 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.
- The default value is null.
(boolean) Property not used. The default value is false.
(int) Property not used. The default value is false.
(String) A custom query to be run when a connection is first created.
- The default value is null.
(String) A semicolon separated list of classnames extending org.apache.tomcat.jdbc.pool.JdbcInterceptor class.
- These interceptors will be inserted as an interceptor into the chain of operations on a java.sql.Connection object.
- The default value is null.
(long) avoid excess validation, only run validation at most at this frequency - time in milliseconds.
- If a connection is due for validation, but has been validated previously within this interval, it will not be validated again.
- The default value is 30000 (30 seconds).
(boolean) Register the pool with JMX or not.
- The default value is true.