Return-Path: X-Original-To: apmail-tomcat-dev-archive@www.apache.org Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1999C7C1D for ; Sat, 22 Oct 2011 21:30:27 +0000 (UTC) Received: (qmail 591 invoked by uid 500); 22 Oct 2011 21:30:26 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 423 invoked by uid 500); 22 Oct 2011 21:30:26 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 285 invoked by uid 99); 22 Oct 2011 21:30:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Oct 2011 21:30:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Oct 2011 21:30:21 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D192C238888F for ; Sat, 22 Oct 2011 21:30:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1187811 [1/4] - in /tomcat/trunk/modules/jdbc-pool: ./ doc/ src/main/java/org/apache/tomcat/jdbc/naming/ src/main/java/org/apache/tomcat/jdbc/pool/ src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ src/main/java/org/apache/tomcat/jdbc... Date: Sat, 22 Oct 2011 21:29:57 -0000 To: dev@tomcat.apache.org From: markt@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111022213001.D192C238888F@eris.apache.org> Author: markt Date: Sat Oct 22 21:29:55 2011 New Revision: 1187811 URL: http://svn.apache.org/viewvc?rev=1187811&view=rev Log: Trailing whitespace removal from /modules/jdbc-pool Modified: tomcat/trunk/modules/jdbc-pool/build.xml tomcat/trunk/modules/jdbc-pool/doc/changelog.xml tomcat/trunk/modules/jdbc-pool/doc/jdbc-pool.xml tomcat/trunk/modules/jdbc-pool/pom.xml tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/naming/GenericNamingResourcesFactory.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSource.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/JdbcInterceptor.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/MultiLockFairBlockingQueue.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolConfiguration.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolUtilities.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ProxyConnection.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/TrapException.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/Validator.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ConnectionState.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimer.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/SlowQueryReport.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/SlowQueryReportJmx.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementDecoratorInterceptor.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementFinalizer.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/mbeans-descriptors.xml tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPoolMBean.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/mbeans-descriptors.xml tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/interceptor/TestInterceptor.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/AbandonPercentageTest.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/AlternateUsernameTest.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/Async0IdleTestBug50477.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/BorrowWaitTest.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/Bug50571.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/Bug50805.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/CheckOutThreadTest.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/ConnectCountTest.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/CreateTestTable.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/DefaultProperties.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/DefaultTestCase.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/FairnessTest.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/JmxPasswordTest.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/SimplePOJOAsyncExample.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/SimplePOJOExample.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/StarvationTest.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/StatementFinalizerTest.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestAsyncQueue.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestConcurrency.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestConnectionState.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestException.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestGCClose.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestGetConnection.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestInterceptorShortName.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestSizePreservation.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestSlowQueryReport.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestStatementCache.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TestSuspectTimeout.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/TwoDataSources.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/driver/Connection.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/driver/Driver.java tomcat/trunk/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/test/driver/ResultSet.java Modified: tomcat/trunk/modules/jdbc-pool/build.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/build.xml?rev=1187811&r1=1187810&r2=1187811&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/build.xml (original) +++ tomcat/trunk/modules/jdbc-pool/build.xml Sat Oct 22 21:29:55 2011 @@ -52,7 +52,7 @@ - + @@ -64,7 +64,7 @@ - + @@ -75,12 +75,12 @@ - + - + @@ -112,7 +112,7 @@ - + - + @@ -205,7 +205,7 @@ - + @@ -226,7 +226,7 @@ - + - + - + @@ -255,7 +255,7 @@ - + @@ -270,7 +270,7 @@ - + @@ -304,18 +304,18 @@ - + - + - - + + - + @@ -342,7 +342,7 @@ - + @@ -351,7 +351,7 @@ - + @@ -359,16 +359,16 @@ - + - + --> @@ -401,10 +401,10 @@ - + - + @@ -434,7 +434,7 @@ Creating test table for test purposes. - + @@ -446,7 +446,7 @@ - + Performance and fairness tests. @@ -487,9 +487,9 @@ - + - + Testing:${test} @@ -506,6 +506,6 @@ - + Modified: tomcat/trunk/modules/jdbc-pool/doc/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/doc/changelog.xml?rev=1187811&r1=1187810&r2=1187811&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/doc/changelog.xml (original) +++ tomcat/trunk/modules/jdbc-pool/doc/changelog.xml Sat Oct 22 21:29:55 2011 @@ -109,7 +109,7 @@
- 720253 Document how to use interceptors + 720253 Document how to use interceptors 717972 Added an interceptor that will clean up non closed statements when a connection is returned to the pool. (org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer) 713763 Improve connection state handling 713763 Improve connection state handling Modified: tomcat/trunk/modules/jdbc-pool/doc/jdbc-pool.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/doc/jdbc-pool.xml?rev=1187811&r1=1187810&r2=1187811&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/doc/jdbc-pool.xml (original) +++ tomcat/trunk/modules/jdbc-pool/doc/jdbc-pool.xml Sat Oct 22 21:29:55 2011 @@ -32,7 +32,7 @@
-

The JDBC Connection Pool org.apache.tomcat.jdbc.pool +

The JDBC Connection Pool org.apache.tomcat.jdbc.pool is a replacement or an alternative to the commons-dbcp connection pool.

@@ -45,15 +45,15 @@ Even with the enormous optimizations of the synchronized statement in Java 6, commons-dbcp still suffers in speed and concurrency.
  • commons-dbcp is complex, over 60 classes. tomcat-jdbc-pool, core is 8 classes, hence modifications for future requirement will require much less changes. This is all you need to run the connection pool itself, the rest is gravy.
  • -
  • commons-dbcp uses static interfaces. This means you can't compile it with JDK 1.6, or if you run on JDK 1.6/1.7 you will get +
  • commons-dbcp uses static interfaces. This means you can't compile it with JDK 1.6, or if you run on JDK 1.6/1.7 you will get NoSuchMethodException for all the methods not implemented, even if the driver supports it.
  • The commons-dbcp has become fairly stagnant. Sparse updates, releases, and new feature support.
  • It's not worth rewriting over 60 classes, when something as a connection pool can be accomplished with as a much simpler implementation.
  • Tomcat jdbc pool implements a fairness option not available in commons-dbcp and still performs faster than commons-dbcp
  • -
  • Tomcat jdbc pool implements the ability retrieve a connection asynchronously, without adding additional threads to the library itself
  • +
  • Tomcat jdbc pool implements the ability retrieve a connection asynchronously, without adding additional threads to the library itself
  • Tomcat jdbc pool is a Tomcat module, it depends on Tomcat JULI, a simplified logging framework used in Tomcat.
  • Retrieve the underlying connection using the javax.sql.PooledConnection interface.
  • -
  • Starvation proof. If a pool is empty, and threads are waiting for a connection, when a connection is returned, +
  • Starvation proof. If a pool is empty, and threads are waiting for a connection, when a connection is returned, the pool will awake the correct thread waiting. Most pools will simply starve.
  • @@ -61,34 +61,34 @@

    Features added over other connection pool implementations

    1. Support for highly concurrent environments and multi core/cpu systems.
    2. -
    3. Dynamic implementation of interface, will support java.sql and javax.sql interfaces for +
    4. Dynamic implementation of interface, will support java.sql and javax.sql interfaces for your runtime environment (as long as your JDBC driver does the same), even when compiled with a lower version of the JDK.
    5. -
    6. Validation intervals - we don't have to validate every single time we use the connection, we can do this +
    7. Validation intervals - we don't have to validate every single time we use the connection, we can do this when we borrow or return the connection, just not more frequent than an interval we can configure.
    8. Run-Once query, a configurable query that will be run only once, when the connection to the database is established. Very useful to setup session settings, that you want to exist during the entire time the connection is established.
    9. Ability to configure custom interceptors. This allows you to write custom interceptors to enhance the functionality. You can use interceptors to gather query stats, - cache session states, reconnect the connection upon failures, retry queries, cache query results, and so on. + cache session states, reconnect the connection upon failures, retry queries, cache query results, and so on. Your options are endless and the interceptors are dynamic, not tied to a JDK version of a java.sql/javax.sql interface.
    10. High performance - we will show some differences in performance later on
    11. -
    12. Extremely simple, due to the very simplified implementation, the line count and source file count are very low, compare with c3p0 - that has over 200 source files(last time we checked), Tomcat jdbc has a core of 8 files, the connection pool itself is about half +
    13. Extremely simple, due to the very simplified implementation, the line count and source file count are very low, compare with c3p0 + that has over 200 source files(last time we checked), Tomcat jdbc has a core of 8 files, the connection pool itself is about half that. As bugs may occur, they will be faster to track down, and easier to fix. Complexity reduction has been a focus from inception.
    14. -
    15. Asynchronous connection retrieval - you can queue your request for a connection and receive a Future<Connection> back.
    16. -
    17. Better idle connection handling. Instead of closing connections directly, it can still pool connections and sizes the idle pool with a smarter algorithm.
    18. +
    19. Asynchronous connection retrieval - you can queue your request for a connection and receive a Future<Connection> back.
    20. +
    21. Better idle connection handling. Instead of closing connections directly, it can still pool connections and sizes the idle pool with a smarter algorithm.
    22. You can decide at what moment connections are considered abandoned, is it when the pool is full, or directly at a timeout by specifying a pool usage threshold. -
    23. +
    24. The abandon connection timer will reset upon a statement/query activity. Allowing a connections that is in use for a long time to not timeout. This is achieved using the ResetAbandonedTimer -
    25. +
    26. Close connections after they have been connected for a certain time. Age based close upon return to the pool. -
    27. +
    28. Get JMX notifications and log entries when connections are suspected for being abandoned. This is similar to - the removeAbandonedTimeout but it doesn't take any action, only reports the information. - This is achieved using the suspectTimeout attribute.
    29. -
    30. Connections can be retrieved from a java.sql.Driver, javax.sql.DataSource or javax.sql.XADataSource + the removeAbandonedTimeout but it doesn't take any action, only reports the information. + This is achieved using the suspectTimeout attribute.
    31. +
    32. Connections can be retrieved from a java.sql.Driver, javax.sql.DataSource or javax.sql.XADataSource This is achieved using the dataSource and dataSourceJNDI attributes.
    33. XA connection support
    @@ -98,47 +98,47 @@

    - Usage of the Tomcat connection pool has been made to be as simple as possible, for those of you that are familiar with commons-dbcp, the - transition will be very simple. Moving from other connection pools is also fairly straight forward. + Usage of the Tomcat connection pool has been made to be as simple as possible, for those of you that are familiar with commons-dbcp, the + transition will be very simple. Moving from other connection pools is also fairly straight forward.

    The Tomcat connection pool offers a few additional features over what most other pools let you do:

    • initSQL - the ability to run a SQL statement exactly once, when the connection is created
    • validationInterval - in addition to running validations on connections, avoid running them too frequently.
    • -
    • jdbcInterceptors - flexible and pluggable interceptors to create any customizations around the pool, +
    • jdbcInterceptors - flexible and pluggable interceptors to create any customizations around the pool, the query execution and the result set handling. More on this in the advanced section.
    • fairQueue - Set the fair flag to true to achieve thread fairness or to use asynchronous connection retrieval
    • -
    +

    The Tomcat Connection pool is configured as a resource described in The Tomcat JDBC documentation - With the only difference being that you have to specify the factory attribute and set the value to + With the only difference being that you have to specify the factory attribute and set the value to org.apache.tomcat.jdbc.pool.DataSourceFactory

    - The connection pool only has another dependency, and that is on tomcat-juli.jar. - To configure the pool in a stand alone project using bean instantiation, the bean to instantiate is + The connection pool only has another dependency, and that is on tomcat-juli.jar. + To configure the pool in a stand alone project using bean instantiation, the bean to instantiate is org.apache.tomcat.jdbc.pool.DataSource. The same attributes (documented below) as you use to configure a connection pool as a JNDI resource, are used to configure a data source as a bean.

    - The connection pool object exposes an MBean that can be registered. + The connection pool object exposes an MBean that can be registered. In order for the connection pool object to create the MBean, the flag jmxEnabled has to be set to true. This doesn't imply that the pool will be registered with an MBean server, merely that the MBean is created. - In a container like Tomcat, Tomcat itself registers the DataSource with the MBean server, the - org.apache.tomcat.jdbc.pool.DataSource object will then register the actual + In a container like Tomcat, Tomcat itself registers the DataSource with the MBean server, the + org.apache.tomcat.jdbc.pool.DataSource object will then register the actual connection pool MBean. If you're running outside of a container, you can register the DataSource yourself under any object name you specify, and it propagates the registration to the underlying pool.

    - +

    To provide a very simple switch to and from commons-dbcp and tomcat-jdbc-pool, @@ -158,7 +158,7 @@

    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.)

    @@ -184,7 +184,7 @@

    (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 + from the same classloader as tomcat-jdbc.jar

    @@ -206,10 +206,10 @@ -

    (int) The maximum number of connections that should be kept in the pool at all times. +

    (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 + Idle connections are checked periodically (if enabled) and + connections that been idle for longer than minEvictableIdleTimeMillis will be released. (also see testWhileIdle)

    @@ -227,15 +227,15 @@ -

    (int) 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. +

    (int) 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. +

    (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 In order to have a more efficient validation, see validationInterval Default value is false @@ -250,22 +250,22 @@ -

    (boolean) The indication of whether objects will be validated by the idle object evictor (if any). +

    (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 + 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. +

    (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)

    - +

    (String) The name of a class which implements the org.apache.tomcat.jdbc.pool.Validator interface and @@ -276,10 +276,10 @@ com.mycompany.project.SimpleValidator.

    - + -

    (int) 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 +

    (int) 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).

    @@ -289,7 +289,7 @@ -

    (int) The minimum amount of time an object may sit idle in the pool before it is eligible for eviction. +

    (int) The minimum amount of time an object may sit idle in the pool before it is eligible for eviction. The default value is 60000 (60 seconds).

    @@ -301,15 +301,15 @@

    (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 + 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.

    -

    (int) 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 +

    (int) 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.

    @@ -322,7 +322,7 @@

    (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. + NOTE - The "user" and "password" properties will be passed explicitly, so they do not need to be included here. The default value is null.

    @@ -333,7 +333,7 @@

    (int) Property not used. The default value is false.

    - +
    @@ -343,7 +343,7 @@ -

    (String) A custom query to be run when a connection is first created. +

    (String) A custom query to be run when a connection is first created. The default value is null.

    @@ -359,18 +359,18 @@

    (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. + 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. +

    (boolean) Register the pool with JMX or not. The default value is true.

    (boolean) Set to true if you wish that calls to getConnection should be treated - fairly in a true FIFO fashion. This uses the org.apache.tomcat.jdbc.pool.FairBlockingQueue + fairly in a true FIFO fashion. This uses the org.apache.tomcat.jdbc.pool.FairBlockingQueue implementation for the list of the idle connections. The default value is true. This flag is required when you want to use asynchronous connection retrieval.
    Setting this flag ensures that threads receive connections in the order they arrive.
    @@ -404,25 +404,25 @@

    (boolean) Set to true if you wish the ProxyConnection class to use String.equals and set to false when you wish to use == when comparing method names. This property does not apply to added interceptors as those are configured individually. The default value is true. -

    -
    +

    +

    (int) Timeout value in seconds. Default value is 0.
    Similar to to the removeAbandonedTimeout value but instead of treating the connection - as abandoned, and potentially closing the connection, this simply logs the warning if - logAbandoned is set to true. If this value is equal or less than 0, no suspect + as abandoned, and potentially closing the connection, this simply logs the warning if + logAbandoned is set to true. If this value is equal or less than 0, no suspect checking will be performed. Suspect checking only takes place if the timeout value is larger than 0 and the connection was not abandoned or if abandon check is disabled. If a connection is suspect a WARN message gets - logged and a JMX notification gets sent once. + logged and a JMX notification gets sent once.

    -

    (boolean) By default, the jdbc-pool will ignore the +

    (boolean) By default, the jdbc-pool will ignore the DataSource.getConnection(username,password) call, and simply return a previously pooled connection under the globally configured properties username and password, for performance reasons. The pool can however be used with different credentials each time a connection is used. Should you request a connection with the credentials user1/password1 and the connection was previously connected using user2/password2, the connection will be closed, and reopened with the requested credentials. This way, the pool size is still managed - on a global level, and not on a per schema level. To enable the functionality described in the + on a global level, and not on a per schema level. To enable the functionality described in the DataSource.getConnection(username,password) call, simply set the property alternateUsernameAllowed to true.
    The default value is false.
    @@ -430,14 +430,14 @@

    -

    (javax.sql.DataSource) +

    (javax.sql.DataSource)

    -

    (String) +

    (String)

    -
    +
    @@ -448,19 +448,19 @@ in order for the system to avoid not needed roundtrips to the database.

    Further interceptors will be added to the core of the pool as the need arises. Contributions are always welcome!

    -

    Interceptors are of course not limited to just java.sql.Connection but can be used to wrap any - of the results from a method invokation as well. You could build query performance analyzer that provides JMX notifications when a +

    Interceptors are of course not limited to just java.sql.Connection but can be used to wrap any + of the results from a method invokation as well. You could build query performance analyzer that provides JMX notifications when a query is running longer than the expected time.

    Configuring JDBC interceptors is done using the jdbcInterceptors property. - The property contains a list of semi colon separated class names. If the classname if not fully qualified it will be prefixed with the + The property contains a list of semi colon separated class names. If the classname if not fully qualified it will be prefixed with the org.apache.tomcat.jdbc.pool.interceptor. prefix.
    Example:
    jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
    - is the same as + is the same as
    jdbcInterceptors="ConnectionState;StatementFinalizer"

    @@ -469,7 +469,7 @@ jdbcInterceptors="ConnectionState;StatementFinalizer(useEquals=true)"
    -

    +

    Abstract base class for all interceptors, can not be instantiated.

    @@ -480,34 +480,34 @@ The default value is true.

    - +

    Caches the connection for the following attributes autoCommit, readOnly, transactionIsolation and catalog. It is a performance enhancement to avoid roundtrip to the database when getters are called or setters are called with an already set value. -

    +

    - +

    Keeps track of all statements created using createStatement, prepareStatement or prepareCall and closes these statements when the connection is returned to the pool. -

    +

    - +

    See 48392. Interceptor to wrap statements and result sets in order to prevent access to the actual connection using the methods ResultSet.getStatement().getConnection() and Statement.getConnection() -

    +

    - +

    Keeps track of query performance and issues log entries when queries exceed a time threshold of fail. The log level used is WARN -

    +

    (int as String) The number of milliseconds a query has to exceed before issuing a log alert. @@ -515,11 +515,11 @@

    -

    (int as String) The maximum number of queries to keep track of in order to preserve memory space +

    (int as String) The maximum number of queries to keep track of in order to preserve memory space The default value is 1000.

    -
    +

    Extends the SlowQueryReport and in addition to log entries it issues JMX notification @@ -527,7 +527,7 @@ This class uses Tomcat's JMX engine so it wont work outside of the Tomcat container. By default, JMX notifications are sent through the ConnectionPool mbean if it is enabled. The SlowQueryReportJmx can also register an MBean if notifyPool=false -

    +

    (boolean as String) Set to false if you want JMX notifications to go to the SlowQueryReportJmx MBean @@ -541,10 +541,10 @@ The abandoned timer starts when a connection is checked out from the pool. This means if you have a 30second timeout and run 10x10second queries using the connection it will be marked abandoned and potentially reclaimed depending on the abandonWhenPercentageFull - attribute. - Using this interceptor it will reset the checkout timer every time you perform an operation on the connection or execute a + attribute. + Using this interceptor it will reset the checkout timer every time you perform an operation on the connection or execute a query successfully. -

    +

    @@ -553,17 +553,17 @@

    Other examples of Tomcat configuration for JDBC usage can be found in the Tomcat documentation.

    -

    Here is a simple example of how to create and use a data source.

    +

    Here is a simple example of how to create and use a data source.

    import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; - + import org.apache.tomcat.jdbc.pool.DataSource; import org.apache.tomcat.jdbc.pool.PoolProperties; - + public class SimplePOJOExample { - + public static void main(String[] args) throws Exception { PoolProperties p = new PoolProperties(); p.setUrl("jdbc:mysql://localhost:3306/mysql"); @@ -588,8 +588,8 @@ p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"+ "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"); DataSource datasource = new DataSource(); - datasource.setPoolProperties(p); - + datasource.setPoolProperties(p); + Connection con = null; try { con = datasource.getConnection(); @@ -606,16 +606,16 @@ if (con!=null) try {con.close();}catch (Exception ignore) {} } } - + }

    And here is an example on how to configure a resource for JNDI lookups

    - <Resource name="jdbc/TestDB" - auth="Container" - type="javax.sql.DataSource" + <Resource name="jdbc/TestDB" + auth="Container" + type="javax.sql.DataSource" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" testWhileIdle="true" testOnBorrow="true" @@ -623,37 +623,37 @@ validationQuery="SELECT 1" validationInterval="30000" timeBetweenEvictionRunsMillis="30000" - maxActive="100" - minIdle="10" - maxWait="10000" + maxActive="100" + minIdle="10" + maxWait="10000" initialSize="10" removeAbandonedTimeout="60" removeAbandoned="true" logAbandoned="true" - minEvictableIdleTimeMillis="30000" + minEvictableIdleTimeMillis="30000" jmxEnabled="true" jdbcInterceptors= "org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer" - username="root" - password="password" + username="root" + password="password" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/mysql"/> - + - +
    -

    The Tomcat JDBC connection pool supports asynchronous connection retrieval without adding additional threads to the +

    The Tomcat JDBC connection pool supports asynchronous connection retrieval without adding additional threads to the pool library. It does this by adding a method to the data source called Future<Connection> getConnectionAsync(). In order to use the async retrieval, two conditions must be met:
    1. You must configure the fairQueue property to be true.
    2. You will have to cast the data source to org.apache.tomcat.jdbc.pool.DataSource
    An example of using the async feature is show below. - + Connection con = null; - try { + try { Future<Connection> future = datasource.getConnectionAsync(); while (!future.isDone()) { System.out.println("Connection is not yet available. Do some background work"); @@ -663,7 +663,7 @@ Thread.currentThread().interrupted(); } } - con = future.get(); //should return instantly + con = future.get(); //should return instantly Statement st = con.createStatement(); ResultSet rs = st.executeQuery("select * from user"); @@ -672,38 +672,38 @@

    Interceptors are a powerful way to enable, disable or modify functionality on a specific connection or its sub components. There are many different use cases for when interceptors are useful. By default, and for performance reasons, the connection pool is stateless. - The only state the pool itself inserts are defaultAutoCommit, defaultReadOnly, defaultTransactionIsolation, defaultCatalog if + The only state the pool itself inserts are defaultAutoCommit, defaultReadOnly, defaultTransactionIsolation, defaultCatalog if these are set. These 4 properties are only set upon connection creation. Should these properties be modified during the usage of the connection, the pool itself will not reset them.

    -

    An interceptor has to extend the org.apache.tomcat.jdbc.pool.JdbcInterceptor class. This class is fairly simple, +

    An interceptor has to extend the org.apache.tomcat.jdbc.pool.JdbcInterceptor class. This class is fairly simple, You will need to have a no arg constructor

    - + public JdbcInterceptor() { }

    - When a connection is borrowed from the pool, the interceptor can initialize or in some other way react to the event by implementing the + When a connection is borrowed from the pool, the interceptor can initialize or in some other way react to the event by implementing the - + public abstract void reset(ConnectionPool parent, PooledConnection con); - method. This method gets called with two parameters, a reference to the connection pool itself ConnectionPool parent + method. This method gets called with two parameters, a reference to the connection pool itself ConnectionPool parent and a reference to the underlying connection PooledConnection con.

    - When a method on the java.sql.Connection object is invoked, it will cause the + When a method on the java.sql.Connection object is invoked, it will cause the public Object invoke(Object proxy, Method method, Object[] args) throws Throwable method to get invoked. The Method method is the actual method invoked, and Object[] args are the arguments. - To look at a very simple example, where we demonstrate how to make the invokation to java.sql.Connection.close() a noop + To look at a very simple example, where we demonstrate how to make the invokation to java.sql.Connection.close() a noop if the connection has been closed - + if (CLOSE_VAL==method.getName()) { if (isClosed()) return null; //noop for already closed. - } + } return super.invoke(proxy,method,args); There is an observation being made. It is the comparison of the method name. One way to do this would be to do @@ -712,13 +712,13 @@ According to the JVM spec, method names and static final String end up in a shared constant pool, so the reference comparison should work. One could of course do this as well: - + if (compare(CLOSE_VAL,method)) { if (isClosed()) return null; //noop for already closed. - } + } return super.invoke(proxy,method,args); - The compare(String,Method) will use the useEquals flag on an interceptor and do either reference comparison or + The compare(String,Method) will use the useEquals flag on an interceptor and do either reference comparison or a string value comparison when the useEquals=true flag is set.

    Pool start/stop
    @@ -727,21 +727,21 @@ public void poolStarted(ConnectionPool pool) { } - + public void poolClosed(ConnectionPool pool) { } When overriding these methods, don't forget to call super if you are extending a class other than JdbcInterceptor -

    +

    Configuring interceptors
    Interceptors are configured using the jdbcInterceptors property or the setJdbcInterceptors method. An interceptor can have properties, and would be configured like this String jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState(useEquals=true,fast=yes)" - -

    + +

    Interceptor properties
    - Since interceptors can have properties, you need to be able to read the values of these properties within your + Since interceptors can have properties, you need to be able to read the values of these properties within your interceptor. Taking an example like the one above, you can override the setProperties method. public void setProperties(Map<String, InterceptorProperty> properties) { @@ -766,7 +766,7 @@

    - +
    @@ -792,7 +792,7 @@ ant dist (creates a release package) ant test (runs tests, expects a test database to be setup) -

    +

    Modified: tomcat/trunk/modules/jdbc-pool/pom.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/pom.xml?rev=1187811&r1=1187810&r2=1187811&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/pom.xml (original) +++ tomcat/trunk/modules/jdbc-pool/pom.xml Sat Oct 22 21:29:55 2011 @@ -7,7 +7,7 @@ apache 9 - + org.apache.tomcat jdbc-pool 1.2-SNAPSHOT @@ -15,11 +15,11 @@ jdbc-pool http://people.apache.org/~fhanik/jdbc-pool/ - + UTF-8 - + Development List @@ -34,12 +34,12 @@ users@tomcat.apache.org - + scm:svn:https://svn.apache.org/repos/asf/tomcat/trunk/modules/jdbc-pool scm:svn:https://svn.apache.org/repos/asf/tomcat/trunk/modules/jdbc-pool http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool - + @@ -86,8 +86,8 @@ - - + + org.apache.maven.plugins maven-gpg-plugin @@ -122,7 +122,7 @@ - + org.apache.maven.plugins maven-javadoc-plugin @@ -134,7 +134,7 @@ - - - + + + Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/naming/GenericNamingResourcesFactory.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/naming/GenericNamingResourcesFactory.java?rev=1187811&r1=1187810&r2=1187811&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/naming/GenericNamingResourcesFactory.java (original) +++ tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/naming/GenericNamingResourcesFactory.java Sat Oct 22 21:29:55 2011 @@ -43,11 +43,11 @@ import org.apache.juli.logging.LogFactor * serverName="localhost" * port="1527"/> * - * + * */ public class GenericNamingResourcesFactory implements ObjectFactory { private static final Log log = LogFactory.getLog(GenericNamingResourcesFactory.class); - + @Override public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception { if ((obj == null) || !(obj instanceof Reference)) { @@ -55,10 +55,10 @@ public class GenericNamingResourcesFacto } Reference ref = (Reference) obj; Enumeration refs = ref.getAll(); - + String type = ref.getClassName(); Object o = Class.forName(type).newInstance(); - + while (refs.hasMoreElements()) { RefAddr addr = refs.nextElement(); String param = addr.getType(); @@ -67,7 +67,7 @@ public class GenericNamingResourcesFacto value = addr.getContent().toString(); } if (setProperty(o, param, value,false)) { - + } else { log.debug("Property not configured["+param+"]. No setter found on["+o+"]."); } @@ -159,9 +159,9 @@ public class GenericNamingResourcesFacto if (methods[i].getReturnType()==Boolean.TYPE){ setPropertyMethodBool = methods[i]; }else { - setPropertyMethodVoid = methods[i]; + setPropertyMethodVoid = methods[i]; } - + } } @@ -205,8 +205,8 @@ public class GenericNamingResourcesFacto o.getClass() + " " + name + "=" + value + ")", ie); } return false; - } - + } + public static String capitalize(String name) { if (name == null || name.length() == 0) { return name; Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java?rev=1187811&r1=1187810&r2=1187811&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java (original) +++ tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java Sat Oct 22 21:29:55 2011 @@ -42,7 +42,7 @@ import org.apache.juli.logging.LogFactor * Implementation of simple connection pool. * The ConnectionPool uses a {@link PoolProperties} object for storing all the meta information about the connection pool. * As the underlying implementation, the connection pool uses {@link java.util.concurrent.BlockingQueue} to store active and idle connections. - * A custom implementation of a fair {@link FairBlockingQueue} blocking queue is provided with the connection pool itself. + * A custom implementation of a fair {@link FairBlockingQueue} blocking queue is provided with the connection pool itself. * @author Filip Hanik * @version 1.0 */ @@ -52,7 +52,7 @@ public class ConnectionPool { * Prefix type for JMX registration */ public static final String POOL_JMX_TYPE_PREFIX = "tomcat.jdbc:type="; - + /** * Logger */ @@ -104,17 +104,17 @@ public class ConnectionPool { * Executor service used to cancel Futures */ private ThreadPoolExecutor cancellator = new ThreadPoolExecutor(0,1,1000,TimeUnit.MILLISECONDS,new LinkedBlockingQueue()); - + /** * reference to the JMX mbean */ protected org.apache.tomcat.jdbc.pool.jmx.ConnectionPool jmxPool = null; - + /** * counter to track how many threads are waiting for a connection */ private AtomicInteger waitcount = new AtomicInteger(0); - + //=============================================================================== // PUBLIC METHODS //=============================================================================== @@ -144,7 +144,7 @@ public class ConnectionPool { PooledConnection pc = borrowConnection(0, null, null); if (pc!=null) { return new ConnectionFuture(pc); - } + } }catch (SQLException x) { if (x.getMessage().indexOf("NoWait")<0) { throw x; @@ -161,9 +161,9 @@ public class ConnectionPool { throw new SQLException("Connection pool is misconfigured, doesn't support async retrieval. Set the 'fair' property to 'true'"); } } - + /** - * Borrows a connection from the pool. If a connection is available (in the idle queue) or the pool has not reached + * Borrows a connection from the pool. If a connection is available (in the idle queue) or the pool has not reached * {@link PoolProperties#maxActive maxActive} connections a connection is returned immediately. * If no connection is available, the pool will attempt to fetch a connection for {@link PoolProperties#maxWait maxWait} milliseconds. * @return Connection - a java.sql.Connection/javax.sql.PooledConnection reflection proxy, wrapping the underlying object. @@ -175,14 +175,14 @@ public class ConnectionPool { return setupConnection(con); } - + /** * Borrows a connection from the pool. If a connection is available (in the * idle queue) or the pool has not reached {@link PoolProperties#maxActive * maxActive} connections a connection is returned immediately. If no * connection is available, the pool will attempt to fetch a connection for * {@link PoolProperties#maxWait maxWait} milliseconds. - * + * * @return Connection - a java.sql.Connection/javax.sql.PooledConnection * reflection proxy, wrapping the underlying object. * @throws SQLException @@ -194,7 +194,7 @@ public class ConnectionPool { PooledConnection con = borrowConnection(-1, username, password); return setupConnection(con); } - + /** * Returns the name of this pool * @return String - the name of the pool @@ -202,7 +202,7 @@ public class ConnectionPool { public String getName() { return getPoolProperties().getPoolName(); } - + /** * Return the number of threads waiting for a connection * @return number of threads waiting for a connection @@ -214,7 +214,7 @@ public class ConnectionPool { /** * Returns the pool properties associated with this connection pool * @return PoolProperties - * + * */ public PoolConfiguration getPoolProperties() { return this.poolProperties; @@ -255,12 +255,12 @@ public class ConnectionPool { //=============================================================================== // PROTECTED METHODS //=============================================================================== - - + + /** * configures a pooled connection as a proxy. * This Proxy implements {@link java.sql.Connection} and {@link javax.sql.PooledConnection} interfaces. - * All calls on {@link java.sql.Connection} methods will be propagated down to the actual JDBC connection except for the + * All calls on {@link java.sql.Connection} methods will be propagated down to the actual JDBC connection except for the * {@link java.sql.Connection#close()} method. * @param con a {@link PooledConnection} to wrap in a Proxy * @return a {@link java.sql.Connection} object wrapping a pooled connection. @@ -317,10 +317,10 @@ public class ConnectionPool { } } - + /** * Creates and caches a {@link java.lang.reflect.Constructor} used to instantiate the proxy object. - * We cache this, since the creation of a constructor is fairly slow. + * We cache this, since the creation of a constructor is fairly slow. * @return constructor used to instantiate the wrapper object * @throws NoSuchMethodException */ @@ -433,10 +433,10 @@ public class ConnectionPool { poolCleaner = new PoolCleaner("[Pool-Cleaner]:" + properties.getName(), this, properties.getTimeBetweenEvictionRunsMillis()); poolCleaner.start(); } //end if - + //create JMX MBean if (this.getPoolProperties().isJmxEnabled()) createMBean(); - + //Parse and create an initial set of interceptors. Letting them know the pool has started. //These interceptors will not get any connection. PoolProperties.InterceptorDefinition[] proxies = getPoolProperties().getJdbcInterceptorsAsArray(); @@ -457,7 +457,7 @@ public class ConnectionPool { throw ex; } } - + //initialize the pool with its initial set of members PooledConnection[] initialPool = new PooledConnection[poolProperties.getInitialSize()]; try { @@ -477,7 +477,7 @@ public class ConnectionPool { } //end if } //for } //catch - + closed = false; } @@ -510,7 +510,7 @@ public class ConnectionPool { con.unlock(); } } - + /** * thread safe way to abandon a connection * signals a connection to be abandoned. @@ -564,8 +564,8 @@ public class ConnectionPool { /** * Thread safe way to retrieve a connection from the pool - * @param wait - time to wait, overrides the maxWait from the properties, - * set to -1 if you wish to use maxWait, 0 if you wish no wait time. + * @param wait - time to wait, overrides the maxWait from the properties, + * set to -1 if you wish to use maxWait, 0 if you wish no wait time. * @return PooledConnection * @throws SQLException */ @@ -587,10 +587,10 @@ public class ConnectionPool { //null should never be returned, but was in a previous impl. if (result!=null) return result; } - + //if we get here, see if we need to create one //this is not 100% accurate since it doesn't use a shared - //atomic variable - a connection can become idle while we are creating + //atomic variable - a connection can become idle while we are creating //a new connection if (size.get() < getPoolProperties().getMaxActive()) { //atomic duplicate check @@ -609,7 +609,7 @@ public class ConnectionPool { if (wait==-1) { maxWait = (getPoolProperties().getMaxWait()<=0)?Long.MAX_VALUE:getPoolProperties().getMaxWait(); } - + long timetowait = Math.max(0, maxWait - (System.currentTimeMillis() - now)); waitcount.incrementAndGet(); try { @@ -698,29 +698,29 @@ public class ConnectionPool { /** * Validates and configures a previously idle connection - * @param now - timestamp + * @param now - timestamp * @param con - the connection to validate and configure * @return con * @throws SQLException if a validation error happens */ protected PooledConnection borrowConnection(long now, PooledConnection con, String username, String password) throws SQLException { //we have a connection, lets set it up - + //flag to see if we need to nullify boolean setToNull = false; try { con.lock(); boolean usercheck = con.checkUser(username, password); - + if (con.isReleased()) { return null; } - + if (!con.isDiscarded() && !con.isInitialized()) { //attempt to connect con.connect(); } - + if (usercheck) { if ((!con.isDiscarded()) && con.validate(PooledConnection.VALIDATE_BORROW)) { //set the timestamp @@ -794,7 +794,7 @@ public class ConnectionPool { return false; } } - + /** * Returns a connection to the pool * If the pool is closed, the connection will be released @@ -815,7 +815,7 @@ public class ConnectionPool { con.lock(); if (busy.remove(con)) { - + if (!shouldClose(con,PooledConnection.VALIDATE_RETURN)) { con.setStackTrace(null); con.setTimestamp(System.currentTimeMillis()); @@ -844,7 +844,7 @@ public class ConnectionPool { } //checkIn /** - * Determines if a connection should be abandoned based on + * Determines if a connection should be abandoned based on * {@link PoolProperties#abandonWhenPercentageFull} setting. * @return true if the connection should be abandoned */ @@ -855,7 +855,7 @@ public class ConnectionPool { float perc = poolProperties.getAbandonWhenPercentageFull(); return (used/max*100f)>=perc; } - + /** * Iterates through all the busy connections and checks for connections that have timed out */ @@ -1016,7 +1016,7 @@ public class ConnectionPool { handler=handler.getNext(); } } - + /** * Hook to perform final actions on a pooled connection object once it has been disconnected and will be discarded * @param con @@ -1031,7 +1031,7 @@ public class ConnectionPool { /** * Return the object that is potentially registered in JMX for notifications - * @return the object implementing the {@link org.apache.tomcat.jdbc.pool.jmx.ConnectionPoolMBean} interface + * @return the object implementing the {@link org.apache.tomcat.jdbc.pool.jmx.ConnectionPoolMBean} interface */ public org.apache.tomcat.jdbc.pool.jmx.ConnectionPool getJmxPool() { return jmxPool; @@ -1051,7 +1051,7 @@ public class ConnectionPool { /** * Tread safe wrapper around a future for the regular queue * This one retrieves the pooled connection object - * and performs the initialization according to + * and performs the initialization according to * interceptors and validation rules. * This class is thread safe and is cancellable * @author fhanik @@ -1068,7 +1068,7 @@ public class ConnectionPool { public ConnectionFuture(Future pcf) { this.pcFuture = pcf; } - + public ConnectionFuture(PooledConnection pc) throws SQLException { this.pc = pc; result = ConnectionPool.this.setupConnection(pc); @@ -1118,7 +1118,7 @@ public class ConnectionPool { latch.countDown(); } } else { - //if we reach here, another thread is configuring the actual connection + //if we reach here, another thread is configuring the actual connection latch.await(timeout,unit); //this shouldn't block for long } if (result==null) throw new ExecutionException(cause); @@ -1143,7 +1143,7 @@ public class ConnectionPool { public boolean isDone() { return pc!=null || pcFuture.isDone(); } - + /** * run method to be executed when cancelled by an executor */ @@ -1158,7 +1158,7 @@ public class ConnectionPool { ConnectionPool.log.error("Unable to cancel ConnectionFuture.",x); } } - + } protected class PoolCleaner extends Thread { Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSource.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSource.java?rev=1187811&r1=1187810&r2=1187811&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSource.java (original) +++ tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSource.java Sat Oct 22 21:29:55 2011 @@ -45,7 +45,7 @@ public class DataSource extends DataSour public DataSource() { super(); } - + /** * Constructs a DataSource object wrapping a connection * @param poolProperties @@ -53,10 +53,10 @@ public class DataSource extends DataSour public DataSource(PoolConfiguration poolProperties) { super(poolProperties); } - - - - + + + + //=============================================================================== // JMX Operations - Register the actual pool itself under the tomcat.jdbc domain @@ -103,9 +103,9 @@ public class DataSource extends DataSour }catch (MalformedObjectNameException x) { log.error("Unable to create object name for JDBC pool.",x); } - return name; + return name; } - + /** * Creates the ObjectName for the ConnectionPoolMBean object to be registered * @param original the ObjectName for the DataSource @@ -124,7 +124,7 @@ public class DataSource extends DataSour ObjectName name = new ObjectName(domain,properties); return name; } - + /** * Registers the ConnectionPoolMBean under a unique name based on the ObjectName for the DataSource */ @@ -138,9 +138,9 @@ public class DataSource extends DataSour log.error("Unable to register JDBC pool with JMX",e); } } - + /** - * + * */ protected void unregisterJmx() { try { Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java?rev=1187811&r1=1187810&r2=1187811&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java (original) +++ tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java Sat Oct 22 21:29:55 2011 @@ -62,7 +62,7 @@ public class DataSourceFactory implement protected final static String PROP_DEFAULTREADONLY = "defaultReadOnly"; protected final static String PROP_DEFAULTTRANSACTIONISOLATION = "defaultTransactionIsolation"; protected final static String PROP_DEFAULTCATALOG = "defaultCatalog"; - + protected final static String PROP_DRIVERCLASSNAME = "driverClassName"; protected final static String PROP_PASSWORD = "password"; protected final static String PROP_URL = "url"; @@ -74,48 +74,48 @@ public class DataSourceFactory implement protected final static String PROP_INITIALSIZE = "initialSize"; protected final static String PROP_MAXWAIT = "maxWait"; protected final static String PROP_MAXAGE = "maxAge"; - + protected final static String PROP_TESTONBORROW = "testOnBorrow"; protected final static String PROP_TESTONRETURN = "testOnReturn"; protected final static String PROP_TESTWHILEIDLE = "testWhileIdle"; protected final static String PROP_TESTONCONNECT = "testOnConnect"; protected final static String PROP_VALIDATIONQUERY = "validationQuery"; protected final static String PROP_VALIDATOR_CLASS_NAME = "validatorClassName"; - + protected final static String PROP_TIMEBETWEENEVICTIONRUNSMILLIS = "timeBetweenEvictionRunsMillis"; protected final static String PROP_NUMTESTSPEREVICTIONRUN = "numTestsPerEvictionRun"; protected final static String PROP_MINEVICTABLEIDLETIMEMILLIS = "minEvictableIdleTimeMillis"; - + protected final static String PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED = "accessToUnderlyingConnectionAllowed"; - + protected final static String PROP_REMOVEABANDONED = "removeAbandoned"; protected final static String PROP_REMOVEABANDONEDTIMEOUT = "removeAbandonedTimeout"; protected final static String PROP_LOGABANDONED = "logAbandoned"; protected final static String PROP_ABANDONWHENPERCENTAGEFULL = "abandonWhenPercentageFull"; - + protected final static String PROP_POOLPREPAREDSTATEMENTS = "poolPreparedStatements"; protected final static String PROP_MAXOPENPREPAREDSTATEMENTS = "maxOpenPreparedStatements"; protected final static String PROP_CONNECTIONPROPERTIES = "connectionProperties"; - + protected final static String PROP_INITSQL = "initSQL"; protected final static String PROP_INTERCEPTORS = "jdbcInterceptors"; protected final static String PROP_VALIDATIONINTERVAL = "validationInterval"; protected final static String PROP_JMX_ENABLED = "jmxEnabled"; protected final static String PROP_FAIR_QUEUE = "fairQueue"; - + protected static final String PROP_USE_EQUALS = "useEquals"; protected static final String PROP_USE_CON_LOCK = "useLock"; - + protected static final String PROP_DATASOURCE= "dataSource"; protected static final String PROP_DATASOURCE_JNDI = "dataSourceJNDI"; - + protected static final String PROP_SUSPECT_TIMEOUT = "suspectTimeout"; - + protected static final String PROP_ALTERNATE_USERNAME_ALLOWED = "alternateUsernameAllowed"; - - + + public static final int UNKNOWN_TRANSACTIONISOLATION = -1; - + public static final String OBJECT_NAME = "object_name"; @@ -204,12 +204,12 @@ public class DataSourceFactory implement if (org.apache.tomcat.jdbc.pool.DataSource.class.getName().equals(ref.getClassName())) { ok = true; } - + if (!ok) { log.warn(ref.getClassName()+" is not a valid class name/type for this JNDI factory."); return null; } - + Properties properties = new Properties(); for (int i = 0; i < ALL_PROPERTIES.length; i++) { @@ -223,7 +223,7 @@ public class DataSourceFactory implement return createDataSource(properties,nameCtx,XA); } - + public static PoolConfiguration parsePoolProperties(Properties properties) { PoolConfiguration poolProperties = new PoolProperties(); String value = null; @@ -353,7 +353,7 @@ public class DataSourceFactory implement if (value != null) { poolProperties.setValidationQuery(value); } - + value = properties.getProperty(PROP_VALIDATOR_CLASS_NAME); if (value != null) { poolProperties.setValidatorClassName(value); @@ -423,12 +423,12 @@ public class DataSourceFactory implement if (value != null) { poolProperties.setJmxEnabled(Boolean.parseBoolean(value)); } - + value = properties.getProperty(PROP_FAIR_QUEUE); if (value != null) { poolProperties.setFairQueue(Boolean.parseBoolean(value)); } - + value = properties.getProperty(PROP_USE_EQUALS); if (value != null) { poolProperties.setUseEquals(Boolean.parseBoolean(value)); @@ -438,29 +438,29 @@ public class DataSourceFactory implement if (value != null) { poolProperties.setName(ObjectName.quote(value)); } - + value = properties.getProperty(PROP_ABANDONWHENPERCENTAGEFULL); if (value != null) { poolProperties.setAbandonWhenPercentageFull(Integer.parseInt(value)); } - + value = properties.getProperty(PROP_MAXAGE); if (value != null) { poolProperties.setMaxAge(Long.parseLong(value)); } - + value = properties.getProperty(PROP_USE_CON_LOCK); if (value != null) { poolProperties.setUseLock(Boolean.parseBoolean(value)); } - + value = properties.getProperty(PROP_DATASOURCE); if (value != null) { //this should never happen throw new IllegalArgumentException("Can't set dataSource property as a string, this must be a javax.sql.DataSource object."); - + } - + value = properties.getProperty(PROP_DATASOURCE_JNDI); if (value != null) { poolProperties.setDataSourceJNDI(value); @@ -470,12 +470,12 @@ public class DataSourceFactory implement if (value != null) { poolProperties.setSuspectTimeout(Integer.parseInt(value)); } - + value = properties.getProperty(PROP_ALTERNATE_USERNAME_ALLOWED); if (value != null) { poolProperties.setAlternateUsernameAllowed(Boolean.parseBoolean(value)); } - + return poolProperties; } @@ -526,7 +526,7 @@ public class DataSourceFactory implement poolProperties.setDataSource(jndiDS); } } - + /** *

    Parse properties from the string. Format of the string must be [propertyName=property;]*

    * @param propText --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org