openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1709309 - /openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java
Date Sun, 18 Oct 2015 19:38:42 GMT
Author: hthomann
Date: Sun Oct 18 19:38:42 2015
New Revision: 1709309

URL: http://svn.apache.org/viewvc?rev=1709309&view=rev
Log:
OPENJPA-2609: Sporadic ClassCastException occurs under heavy load when QuerySQLCache is enabled.

Modified:
    openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java

Modified: openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java?rev=1709309&r1=1709308&r2=1709309&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java
(original)
+++ openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PreparedQueryCacheImpl.java
Sun Oct 18 19:38:42 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);



Mime
View raw message