OPENJPA-2609: Sporadic ClassCastException occurs under heavy load when QuerySQLCache is enabled.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.1.x@1709309 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Heath Thomann 2015-10-18 19:38:42 +00:00
parent 42855b69f4
commit 2073783505
1 changed files with 14 additions and 7 deletions

View File

@ -106,18 +106,25 @@ public class PreparedQueryCacheImpl implements PreparedQueryCache {
} }
/** /**
* Cache the given query keyed by its identifier. Does not cache if the * Cache the given query keyed by its identifier. Does not cache if the
* identifier matches any exclusion pattern or has been marked as * identifier matches any exclusion pattern or has been marked as
* non-cachable. Also register the identifier as not cachable against * non-cachable. Also register the identifier as not cachable against the
* the matched exclusion pattern. * matched exclusion pattern.
*/ */
public boolean cache(PreparedQuery q) { public boolean cache(PreparedQuery q) {
lock(false); lock(false);
try { try {
String id = q.getIdentifier(); 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 (Boolean.FALSE.equals(isCachable(id))) {
if (_log != null && _log.isTraceEnabled()) 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; return false;
} }
Exclusion exclusion = getMatchedExclusionPattern(id); Exclusion exclusion = getMatchedExclusionPattern(id);
@ -126,8 +133,8 @@ public class PreparedQueryCacheImpl implements PreparedQueryCache {
return false; return false;
} }
_delegate.put(id, q); _delegate.put(id, q);
if (_log != null && _log.isTraceEnabled()) if (_log != null && _log.isTraceEnabled())
_log.trace(_loc.get("prepared-query-cached", id)); _log.trace(_loc.get("prepared-query-cached", id));
return true; return true;
} finally { } finally {
unlock(false); unlock(false);