db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata ConnectionFactoryDescriptor.java
Date Thu, 17 Feb 2005 13:49:02 GMT
arminw      2005/02/17 05:49:02

  Modified:    src/java/org/apache/ojb/broker/accesslayer
                        ConnectionFactoryPooledImpl.java
               src/java/org/apache/ojb/broker/metadata
                        ConnectionFactoryDescriptor.java
  Log:
  add patch by Ilkka Priha
  </snip>
  We noticed that under heavy load (lack of memory) OJB returns closed Connections into the
pool. This happens when the finalizer activates the finalize method of PersistenceBroker instances.
At least MySQL Connections are already closed at this point (their finalize called as well?).
Closed Connections cause a lot of trouble later on when borrowed back to use from the pool.
  <snip>
  ConnectionFactoryPooledImpl now always check for closed connections when connection was
returned to pool and validation of connection was improved.
  
  Revision  Changes    Path
  1.20      +25 -16    db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java
  
  Index: ConnectionFactoryPooledImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- ConnectionFactoryPooledImpl.java	18 Dec 2004 13:32:10 -0000	1.19
  +++ ConnectionFactoryPooledImpl.java	17 Feb 2005 13:49:02 -0000	1.20
  @@ -59,7 +59,17 @@
       {
           try
           {
  -            this.pool.returnObject(con);
  +            /**
  +             * Patch by Ilkka Priha
  +             * To avoid problems with closed connections we only return unclosed
  +             * connections to pool. We do this test independent from the from the
  +             * commons-pool settings, which also supports validation on return of
  +             * a connecion.
  +             */
  +            if(!con.isClosed())
  +            {
  +                this.pool.returnObject(con);
  +            }
           }
           catch (Exception e)
           {
  @@ -138,24 +148,22 @@
           public boolean validateObject(Object obj)
           {
               Connection con = (Connection) obj;
  -            String query = getJcd().getConnectionFactoryDescriptor().getValidationQuery();
  -            if (query == null || query.trim().equals(""))
  +            boolean isValid = false;
  +            try
               {
  -                try
  -                {
  -                    return !con.isClosed();
  -                }
  -                catch (SQLException e)
  -                {
  -                    log.warn("Connection validation failed: " + e.getMessage());
  -                    if (log.isDebugEnabled()) log.debug(e);
  -                    return false;
  -                }
  +                isValid = !con.isClosed();
               }
  -            else
  +            catch (SQLException e)
               {
  -                return validateConnection(con, query);
  +                log.warn("Connection validation failed: " + e.getMessage());
  +                if (log.isDebugEnabled()) log.debug(e);
  +                isValid = false;
               }
  +            if(isValid && getJcd().getConnectionFactoryDescriptor().getValidationQuery()
!= null)
  +            {
  +                isValid = validateConnection(con , getJcd().getConnectionFactoryDescriptor().getValidationQuery());
  +            }
  +            return isValid;
           }
   
           private boolean validateConnection(Connection conn, String query)
  @@ -165,6 +173,7 @@
               boolean isValid = false;
               if (failedValidationQuery > 100)
               {
  +                --failedValidationQuery;
                   throw new OJBRuntimeException("Validation of connection " + conn + " using
validation query " +
                           query + " failed more than 100 times.");
               }
  
  
  
  1.3       +3 -2      db-ojb/src/java/org/apache/ojb/broker/metadata/ConnectionFactoryDescriptor.java
  
  Index: ConnectionFactoryDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/ConnectionFactoryDescriptor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConnectionFactoryDescriptor.java	15 Nov 2004 22:51:40 -0000	1.2
  +++ ConnectionFactoryDescriptor.java	17 Feb 2005 13:49:02 -0000	1.3
  @@ -20,6 +20,7 @@
   import java.util.Properties;
   
   import org.apache.commons.lang.SystemUtils;
  +import org.apache.commons.lang.StringUtils;
   import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.ojb.broker.accesslayer.ConnectionFactoryPooledImpl;
   
  @@ -62,7 +63,7 @@
   
       public String getValidationQuery()
       {
  -        return validationQuery;
  +        return StringUtils.isEmpty(validationQuery) ? null : validationQuery;
       }
   
       public void setValidationQuery(String validationQuery)
  
  
  

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


Mime
View raw message