db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject cvs commit: db-torque/src/java/org/apache/torque/manager AbstractBaseManager.java MethodResultCache.java
Date Fri, 20 Jun 2003 08:12:50 GMT
dlr         2003/06/20 01:12:50

  Modified:    src/java/org/apache/torque/manager Tag: TORQUE_3_0_BRANCH
                        AbstractBaseManager.java MethodResultCache.java
  Log:
  Backported delta between CVS revision 1.14 and 1.15 of
  AbstractBaseManager.java and 1.16 and 1.17 of MethodResultCache.java
  to the tip of the 3.0 branch (~3.0.2):
  
  Corrected deadly multi-CPU thread deadlock problem discovered by Ed
  Korthof <ed@apache.org> and John McNally <jmcnally@apache.org>.  The
  problem was due to emulation of synchronization using an int counter
  (to improve performance by avoiding Java "synchronized" keyword).
  Post-increment and decrement operators compile to three op codes (with
  Sun's JDK 1.3.1 for Linux), unsafe on a multi-CPU box.
  
  * src/java/org/apache/torque/manager/AbstractBaseManager.java
    lockCache, inGet, cacheGet(), removeInstanceImpl(),
    putInstanceImpl(): Removed use of lockeCache and inGet instance
    fields, replaced by consistent use of Java's "synchronized" keyword
    (on the current instance, "this").
  
    getMethodResultCache(), addCacheListenerImpl(), createSubsetList(),
    readObject(): Added JavaDoc.
  
  * src/java/org/apache/torque/manager/MethodResultCache.java
    lockCache, getImpl(), putImpl(), get(): Removed use of lockeCache
    instance fields, replaced by consistent use of Java's "synchronized"
    keyword (on the current instance, "this").
  
    remove(): Added error messages to several method overloads.
  
  Reviewed by: John McNally
  Issue: PCN19237
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.11.2.1  +40 -52    db-torque/src/java/org/apache/torque/manager/AbstractBaseManager.java
  
  Index: AbstractBaseManager.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/manager/AbstractBaseManager.java,v
  retrieving revision 1.11
  retrieving revision 1.11.2.1
  diff -u -u -r1.11 -r1.11.2.1
  --- AbstractBaseManager.java	29 Nov 2002 13:16:05 -0000	1.11
  +++ AbstractBaseManager.java	20 Jun 2003 08:12:50 -0000	1.11.2.1
  @@ -63,6 +63,7 @@
   import java.util.Iterator;
   import java.io.Serializable;
   import java.io.IOException;
  +import java.io.ObjectInputStream;
   
   import org.apache.commons.collections.FastArrayList;
   import org.apache.jcs.JCS;
  @@ -102,8 +103,6 @@
   
       private String region;
   
  -    private boolean lockCache;
  -    private int inGet;
       private boolean isNew = true;
   
       protected Map validFields;
  @@ -215,18 +214,9 @@
           Persistent om = null;
           if (cache != null)
           {
  -            if (lockCache)
  -            {
  -                synchronized (this)
  -                {
  -                    om = (Persistent) cache.get(key);
  -                }
  -            }
  -            else
  +            synchronized (this)
               {
  -                inGet++;
                   om = (Persistent) cache.get(key);
  -                inGet--;
               }
           }
           return om;
  @@ -256,29 +246,19 @@
           Persistent oldOm = null;
           if (cache != null)
           {
  -            synchronized (this)
  +            try
               {
  -                lockCache = true;
  -                try
  +                synchronized (this)
                   {
                       oldOm = (Persistent) cache.get(key);
  -                    while (inGet > 0)
  -                    {
  -                        Thread.yield();
  -                    }
                       cache.remove(key);
                   }
  -                catch (CacheException ce)
  -                {
  -                    lockCache = false;
  -                    throw new TorqueException(
  -                    "Could not remove from cache due to internal JCS error.",
  -                        ce);
  -                }
  -                finally
  -                {
  -                    lockCache = false;
  -                }
  +            }
  +            catch (CacheException ce)
  +            {
  +                throw new TorqueException
  +                    ("Could not remove from cache due to internal JCS error",
  +                     ce);
               }
           }
           return oldOm;
  @@ -306,28 +286,18 @@
           Persistent oldOm = null;
           if (cache != null)
           {
  -            synchronized (this)
  +            try
               {
  -                lockCache = true;
  -                try
  +                synchronized (this)
                   {
                       oldOm = (Persistent) cache.get(key);
  -                    while (inGet > 0)
  -                    {
  -                        Thread.yield();
  -                    }
                       cache.put(key, om);
                   }
  -                catch (CacheException ce)
  -                {
  -                    lockCache = false;
  -                    throw new TorqueException(
  -                        "Could not cache due to internal JCS error.", ce);
  -                }
  -                finally
  -                {
  -                    lockCache = false;
  -                }
  +            }
  +            catch (CacheException ce)
  +            {
  +                throw new TorqueException
  +                    ("Could not cache due to internal JCS error", ce);
               }
           }
           return oldOm;
  @@ -470,6 +440,9 @@
           }
       }
   
  +    /**
  +     * @return The cache instance.
  +     */
       public MethodResultCache getMethodResultCache()
       {
           if (isNew)
  @@ -494,7 +467,10 @@
       {
       }
   
  -
  +    /**
  +     * 
  +     * @param listener A new listener for cache events.
  +     */
       public void addCacheListenerImpl(CacheListener listener)
       {
           List keys = listener.getInterestedFields();
  @@ -538,6 +514,11 @@
           }
       }
   
  +    /**
  +     * 
  +     * @param key
  +     * @return A subset of the list identified by <code>key</code>.
  +     */
       private synchronized List createSubsetList(String key)
       {
           FastArrayList list = null;
  @@ -597,7 +578,14 @@
           out.defaultWriteObject();
       }
   
  -    private void readObject(java.io.ObjectInputStream in)
  +    /**
  +     * Helper methods for the <code>Serializable</code> interface.
  +     * 
  +     * @param in The stream to read a <code>Serializable</code> from.
  +     * @throws IOException
  +     * @throws ClassNotFoundException
  +     */
  +    private void readObject(ObjectInputStream in)
           throws IOException, ClassNotFoundException
       {
           in.defaultReadObject();
  @@ -611,8 +599,8 @@
           }
           catch (Exception e)
           {
  -            category.error("Cache could not be initialized for region: "
  -                           + region + "after deserialization");
  +            category.error("Cache could not be initialized for region '"
  +                           + region + "' after deserialization");
           }
       }
   }
  
  
  
  1.13.2.1  +19 -57    db-torque/src/java/org/apache/torque/manager/MethodResultCache.java
  
  Index: MethodResultCache.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/manager/MethodResultCache.java,v
  retrieving revision 1.13
  retrieving revision 1.13.2.1
  diff -u -u -r1.13 -r1.13.2.1
  --- MethodResultCache.java	29 Nov 2002 13:16:05 -0000	1.13
  +++ MethodResultCache.java	20 Jun 2003 08:12:50 -0000	1.13.2.1
  @@ -66,7 +66,8 @@
   import org.apache.torque.TorqueException;
   
   /**
  - * This class provides a cache for convenient storage of method results
  + * This class provides a cache for convenient storage of method
  + * results.
    *
    * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
    * @version $Id$
  @@ -81,7 +82,6 @@
           "org.apache.torque.manager.MethodCacheKey";
       private ObjectPool pool;
       private GroupCacheAccess jcsCache;
  -    private boolean lockCache;
       private int inGet;
       private Map groups;
   
  @@ -124,18 +124,9 @@
           Object result = null;
           if (jcsCache != null)
           {
  -            if (lockCache)
  -            {
  -                synchronized (this)
  -                {
  -                    result = jcsCache.getFromGroup(key, key.getGroupKey());
  -                }
  -            }
  -            else
  +            synchronized (this)
               {
  -                inGet++;
                   result = jcsCache.getFromGroup(key, key.getGroupKey());
  -                inGet--;
               }
           }
   
  @@ -160,28 +151,18 @@
           Object old = null;
           if (jcsCache != null)
           {
  -            synchronized (this)
  +            try
               {
  -                lockCache = true;
  -                try
  +                synchronized (this)
                   {
                       old = jcsCache.getFromGroup(key, group);
  -                    while (inGet > 0)
  -                    {
  -                        Thread.yield();
  -                    }
                       jcsCache.putInGroup(key, group, value);
                   }
  -                catch (CacheException ce)
  -                {
  -                    lockCache = false;
  -                    throw new TorqueException(
  -                        "Could not cache due to internal JCS error.", ce);
  -                }
  -                finally
  -                {
  -                    lockCache = false;
  -                }
  +            }
  +            catch (CacheException ce)
  +            {
  +                throw new TorqueException
  +                    ("Could not cache due to internal JCS error", ce);
               }
           }
           return old;
  @@ -195,27 +176,8 @@
           {
               synchronized (this)
               {
  -                lockCache = true;
  -                try
  -                {
  -                    old = jcsCache.getFromGroup(key, key.getGroupKey());
  -                    while (inGet > 0)
  -                    {
  -                        Thread.yield();
  -                    }
  -                    jcsCache.remove(key, key.getGroupKey());
  -                }
  -                // jcs does not throw an exception here, might remove this
  -                catch (Exception ce)
  -                {
  -                    lockCache = false;
  -                    throw new TorqueException(
  -                        "Could not cache due to internal JCS error.", ce);
  -                }
  -                finally
  -                {
  -                    lockCache = false;
  -                }
  +                old = jcsCache.getFromGroup(key, key.getGroupKey());
  +                jcsCache.remove(key, key.getGroupKey());
               }
           }
           return old;
  @@ -520,7 +482,7 @@
               }
               catch (Exception e)
               {
  -                log.error("", e);
  +                log.error("Error removing element", e);
               }
           }
           return result;
  @@ -544,12 +506,12 @@
                   catch (Exception e)
                   {
                       log.warn(
  -                        "Nonfatal error.  Could not return key to pool", e);
  +                        "Nonfatal error: Could not return key to pool", e);
                   }
               }
               catch (Exception e)
               {
  -                log.error("", e);
  +                log.error("Error removing element from cache", e);
               }
           }
           return result;
  @@ -579,7 +541,7 @@
               }
               catch (Exception e)
               {
  -                log.error("", e);
  +                log.error("Error removing element from cache", e);
               }
           }
           return result;
  @@ -602,12 +564,12 @@
                   catch (Exception e)
                   {
                       log.warn(
  -                        "Nonfatal error.  Could not return key to pool", e);
  +                        "Nonfatal error: Could not return key to pool", e);
                   }
               }
               catch (Exception e)
               {
  -                log.error("", e);
  +                log.error("Error removing element from cache", e);
               }
           }
           return result;
  
  
  

Mime
View raw message