Return-Path: Mailing-List: contact turbine-torque-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list turbine-torque-dev@jakarta.apache.org Received: (qmail 2965 invoked by uid 97); 9 Jan 2003 13:53:30 -0000 Received: (qmail 2961 invoked by uid 98); 9 Jan 2003 13:53:29 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Received: (qmail 2942 invoked from network); 9 Jan 2003 13:53:27 -0000 Received: from daedalus.apache.org (HELO apache.org) (63.251.56.142) by nagoya.betaversion.org with SMTP; 9 Jan 2003 13:53:27 -0000 Received: (qmail 16469 invoked by uid 500); 9 Jan 2003 13:52:09 -0000 Received: (qmail 16462 invoked from network); 9 Jan 2003 13:52:09 -0000 Received: from icarus.apache.org (63.251.56.143) by daedalus.apache.org with SMTP; 9 Jan 2003 13:52:09 -0000 Received: (qmail 57690 invoked by uid 1332); 9 Jan 2003 13:52:09 -0000 Date: 9 Jan 2003 13:52:09 -0000 Message-ID: <20030109135209.57689.qmail@icarus.apache.org> From: henning@apache.org To: jakarta-turbine-torque-cvs@apache.org Subject: cvs commit: jakarta-turbine-torque/src/java/org/apache/torque/pool ConnectionPool.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N henning 2003/01/09 05:52:09 Modified: src/java/org/apache/torque/pool ConnectionPool.java Log: Cleaned up the calculation of the various C'tor related timeouts and variables. Introduced a few constants to make this clearer. Start the thread for monitoring only if the log Interval is > 0. Revision Changes Path 1.20 +42 -37 jakarta-turbine-torque/src/java/org/apache/torque/pool/ConnectionPool.java Index: ConnectionPool.java =================================================================== RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/pool/ConnectionPool.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- ConnectionPool.java 9 Jan 2003 13:40:03 -0000 1.19 +++ ConnectionPool.java 9 Jan 2003 13:52:09 -0000 1.20 @@ -84,6 +84,16 @@ */ class ConnectionPool implements ConnectionEventListener { + + /** Default maximum Number of connections from this pool: One */ + public static final int DEFAULT_MAX_CONNECTIONS = 1; + + /** Default Expiry Time for a pool: 1 hour */ + public static final int DEFAULT_EXPIRY_TIME = 60 * 60 * 1000; + + /** Default Connect Wait Timeout: 10 Seconds */ + public static final int DEFAULT_CONNECTION_WAIT_TIMEOUT = 10 * 1000; + /** * Pool containing database connections. */ @@ -112,12 +122,12 @@ /** * The maximum number of database connections that can be created. */ - private int maxConnections; + private int maxConnections = DEFAULT_MAX_CONNECTIONS; /** * The amount of time in milliseconds that a connection will be pooled. */ - private int expiryTime; // 1 hour + private int expiryTime = DEFAULT_EXPIRY_TIME; /** * Counter that keeps track of the number of threads that are in @@ -132,7 +142,7 @@ = Category.getInstance(ConnectionPool.class.getName()); /** Interval (in seconds) that the monitor thread reports the pool state */ - private int logInterval; + private int logInterval = 0; /** Monitor thread reporting the pool state */ private Monitor monitor; @@ -141,7 +151,7 @@ * Amount of time a thread asking the pool for a cached connection will * wait before timing out and throwing an error. */ - private long connectionWaitTimeout; + private long connectionWaitTimeout = DEFAULT_CONNECTION_WAIT_TIMEOUT; /** The ConnectionPoolDataSource */ private ConnectionPoolDataSource cpds; @@ -175,40 +185,35 @@ this.cpds = cpds; this.username = username; this.password = password; - if (maxConnections > 0) - { - this.maxConnections = maxConnections; - } - else - { - this.maxConnections = 1; - } - if (expiryTime > 0) - { - this.expiryTime = expiryTime * 1000; - } - else - { - this.expiryTime = 3600 * 1000; // one hour - } - if (connectionWaitTimeout > 0) - { - this.connectionWaitTimeout = connectionWaitTimeout * 1000; - } - else + + this.maxConnections = + (maxConnections > 0) ? maxConnections : DEFAULT_MAX_CONNECTIONS; + + this.expiryTime = + 1000 * ((expiryTime > 0) ? expiryTime : DEFAULT_EXPIRY_TIME); + + this.connectionWaitTimeout = + 1000 * ((connectionWaitTimeout > 0) + ? connectionWaitTimeout + : DEFAULT_CONNECTION_WAIT_TIMEOUT); + + this.logInterval = 1000 * logInterval; + + if (logInterval > 0) { - this.connectionWaitTimeout = 10 * 1000; // ten seconds - } - this.logInterval = logInterval * 1000; + category.debug("Starting Pool Monitor Thread with Log Interval " + + logInterval + " Milliseconds"); - // Create monitor thread - monitor = new Monitor(); - // Indicate that this is a system thread. JVM will quit only when there - // are no more active user threads. Settings threads spawned internally - // by Torque as daemons allows commandline applications using Torque - // to terminate in an orderly manner. - monitor.setDaemon(true); - monitor.start(); + // Create monitor thread + monitor = new Monitor(); + + // Indicate that this is a system thread. JVM will quit only + // when there are no more active user threads. Settings threads + // spawned internally by Torque as daemons allows commandline + // applications using Torque to terminate in an orderly manner. + monitor.setDaemon(true); + monitor.start(); + } } /**