Author: hthomann
Date: Sun Oct 18 19:48:18 2015
New Revision: 1709310

URL: http://svn.apache.org/viewvc?rev=1709310&view=rev
Log:
OPENJPA-2609: Sporadic ClassCastException occurs under heavy load when 
QuerySQLCache is enabled.  Merged 2.1.x changes to 2.2.1.x.

Modified:
    openjpa/branches/2.2.1.x/   (props changed)
    
openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java

Propchange: openjpa/branches/2.2.1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Oct 18 19:48:18 2015
@@ -1,5 +1,5 @@
 /openjpa/branches/1.0.x:736493
 /openjpa/branches/2.0.x:1419659,1484136,1484287,1504611
-/openjpa/branches/2.1.x:1415379,1415398,1436150,1469090,1469949,1484300,1484313,1485010,1505837,1513249,1517838,1529241,1530146,1533218,1533280,1539188,1569528,1575444,1591536,1614935,1636464,1648430,1655218,1662610,1673300,1673491,1686894,1709201
+/openjpa/branches/2.1.x:1415379,1415398,1436150,1469090,1469949,1484300,1484313,1485010,1505837,1513249,1517838,1529241,1530146,1533218,1533280,1539188,1569528,1575444,1591536,1614935,1636464,1648430,1655218,1662610,1673300,1673491,1686894,1709201,1709309
 /openjpa/branches/2.2.x:1580898,1580939,1591681,1641906,1642555,1702143
 
/openjpa/trunk:1416742,1420324,1430117,1431649,1436957,1436960,1448662,1448796,1451369,1456574,1456614,1459091,1461833,1469646,1469649,1469652,1504282,1600757,1603251

Modified: 
openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java
URL: 
http://svn.apache.org/viewvc/openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java?rev=1709310&r1=1709309&r2=1709310&view=diff
==============================================================================
--- 
openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java
 (original)
+++ 
openjpa/branches/2.2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java
 Sun Oct 18 19:48:18 2015
@@ -106,18 +106,25 @@ public class PreparedQueryCacheImpl impl
        }
        
        /**
-        * Cache the given query keyed by its identifier. Does not cache if the 
-        * identifier matches any exclusion pattern or has been marked as 
-        * non-cachable. Also register the identifier as not cachable against 
-        * the matched exclusion pattern.
+        * Cache the given query keyed by its identifier. Does not cache if the
+        * identifier matches any exclusion pattern or has been marked as
+        * non-cachable. Also register the identifier as not cachable against 
the
+        * matched exclusion pattern.
         */
        public boolean cache(PreparedQuery q) {
                lock(false);
                try {
                        String id = q.getIdentifier();
+
+                       // OPENJPA-2609: Make sure another thread didn't add 
the 'id'
+                       // while holding the 'lock'.
+                       if (_delegate.containsKey(id)) {
+                               return false;
+                       }
+
                        if (Boolean.FALSE.equals(isCachable(id))) {
                                if (_log != null && _log.isTraceEnabled())
-                    _log.trace(_loc.get("prepared-query-not-cachable", id));
+                                       
_log.trace(_loc.get("prepared-query-not-cachable", id));
                                return false;
                        }
                        Exclusion exclusion = getMatchedExclusionPattern(id);
@@ -126,8 +133,8 @@ public class PreparedQueryCacheImpl impl
                                return false;
                        }
                        _delegate.put(id, q);
-            if (_log != null && _log.isTraceEnabled())
-                _log.trace(_loc.get("prepared-query-cached", id));
+                       if (_log != null && _log.isTraceEnabled())
+                               _log.trace(_loc.get("prepared-query-cached", 
id));
                        return true;
                } finally {
                        unlock(false);


Reply via email to