You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2004/04/14 19:33:28 UTC

cvs commit: james-server/src/java/org/apache/james/util/mordred JdbcDataSource.java

noel        2004/04/14 10:33:28

  Modified:    src/java/org/apache/james/util/mordred Tag: branch_2_1_fcs
                        JdbcDataSource.java
  Log:
  Fix JAMES-253
  
  Patch applied based upon Marcus Labib's contribution. Enforces synchronized access to the pool.
  
  Also added code based upon his patch to first just log overly long-lived connections, and then close them at a later time. Not sure it is needed, but if the code is ever exercised, it should provide some data on "stuck" connections.
  
  It should be noted that mordred is considered deprecated in favor of DBCP.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.18.4.6  +32 -13    james-server/src/java/org/apache/james/util/mordred/JdbcDataSource.java
  
  Index: JdbcDataSource.java
  ===================================================================
  RCS file: /home/cvs/james-server/src/java/org/apache/james/util/mordred/JdbcDataSource.java,v
  retrieving revision 1.18.4.5
  retrieving revision 1.18.4.6
  diff -u -r1.18.4.5 -r1.18.4.6
  --- JdbcDataSource.java	15 Mar 2004 03:54:23 -0000	1.18.4.5
  +++ JdbcDataSource.java	14 Apr 2004 17:33:28 -0000	1.18.4.6
  @@ -66,6 +66,7 @@
                  DataSourceComponent {
       // The limit that an active connection can be running
       public static final long ACTIVE_CONN_TIME_LIMIT = 60000; // (one minute)
  +    public static final long ACTIVE_CONN_HARD_TIME_LIMIT = 2*ACTIVE_CONN_TIME_LIMIT;
       // How long before you kill off a connection due to inactivity
       public static final long CONN_IDLE_LIMIT        = 600000; // (10 minutes)
       private static final boolean DEEP_DEBUG         = false;
  @@ -308,10 +309,10 @@
        *
        * @deprecated This was left over code from Town... but not exposed in Avalon.
        */
  -    public synchronized void killAllConnections() {
  +    public void killAllConnections() {
           //Just remove the references to all the connections... this will cause them to get
           // finalized before very long. (not an instant shutdown, but that's ok).
  -        pool.clear();
  +        synchronized (pool) { pool.clear(); }
       }
   
       /**
  @@ -387,13 +388,13 @@
        */
       public void run() {
           try {
  -            while(reaperActive) {
  +            while(reaperActive) synchronized (pool) {
                   for(int i = 0; i < pool.size(); i++) try {
                       PoolConnEntry entry = (PoolConnEntry)pool.elementAt(i);
                       long age            = System.currentTimeMillis() - entry.getLastActivity();
                       synchronized(entry) {
                           if((entry.getStatus() == PoolConnEntry.ACTIVE) &&
  -                           (age > ACTIVE_CONN_TIME_LIMIT)) {
  +                           (age > ACTIVE_CONN_HARD_TIME_LIMIT)) {
                               StringBuffer logBuffer =
                                   new StringBuffer(128)
                                           .append(" ***** connection ")
  @@ -401,13 +402,29 @@
                                           .append(" is way too old: ")
                                           .append(age)
                                           .append(" > ")
  -                                        .append(ACTIVE_CONN_TIME_LIMIT);
  +                                        .append(ACTIVE_CONN_HARD_TIME_LIMIT)
  +                                        .append(" and will be closed.");
                               getLogger().info(logBuffer.toString());
                               // This connection is way too old...
                               // kill it no matter what
                               finalizeEntry(entry);
                               continue;
                           }
  +                        if((entry.getStatus() == PoolConnEntry.ACTIVE) &&
  +                           (age > ACTIVE_CONN_TIME_LIMIT)) {
  +                            StringBuffer logBuffer =
  +                                new StringBuffer(128)
  +                                        .append(" ***** connection ")
  +                                        .append(entry.getId())
  +                                        .append(" is way too old: ")
  +                                        .append(age)
  +                                        .append(" > ")
  +                                        .append(ACTIVE_CONN_TIME_LIMIT);
  +                            getLogger().info(logBuffer.toString());
  +                            // This connection is way too old...
  +                            // just log it for now.
  +                            continue;
  +                        }
                           if((entry.getStatus() == PoolConnEntry.AVAILABLE) &&
                              (age > CONN_IDLE_LIMIT)) {
                               //We've got a connection that's too old... kill it
  @@ -460,7 +477,7 @@
        */
       private PoolConnEntry createConn() throws SQLException {
           PoolConnEntry entry = null;
  -        synchronized(this) {
  +        synchronized(pool) {
               if(connCreationsInProgress > 0) {
                   //We are already creating one in another place
                   return null;
  @@ -516,7 +533,7 @@
               }
               return null;
           } finally {
  -            synchronized(this) {
  +            synchronized(pool) {
                   connCreationsInProgress--;
               }
           }
  @@ -527,11 +544,13 @@
        *
        * @param entry entry
        */
  -    private synchronized void finalizeEntry(PoolConnEntry entry) {
  -        try {
  -            entry.finalize();
  -        } catch(Exception fe) {
  +    private void finalizeEntry(PoolConnEntry entry) {
  +        synchronized(pool) {
  +            try {
  +                entry.finalize();
  +            } catch(Exception fe) {
  +            }
  +            pool.removeElement(entry);
           }
  -        pool.removeElement(entry);
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org