From ee9e2b78a063c8d81c768e747751ca0fdc7cb203 Mon Sep 17 00:00:00 2001 From: Josh Portner Date: Thu, 25 Feb 2021 11:51:21 -0800 Subject: [PATCH 1/2] HW-53073: Allow Thread Interruption for WriteLockManager for release 2.7.6 of eclipselink --- .../internal/helper/WriteLockManager.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/WriteLockManager.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/WriteLockManager.java index 7cc2d566d94..4d9a05e7a44 100644 --- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/WriteLockManager.java +++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/WriteLockManager.java @@ -61,11 +61,18 @@ */ public class WriteLockManager { + private static final Logger logger = Logger.getLogger(WriteLockManager.class.getSimpleName()); + // this will allow us to prevent a readlock thread from looping forever. public static final int MAXTRIES = 10000; public static final int MAX_WAIT = 600000; //10 mins + private static boolean isInterruptionEnabled() { + String value = System.getProperty("interruptionEnabled"); + return parseBoolean(value); + } + /* This attribute stores the list of threads that have had a problem acquiring locks */ /* the first element in this list will be the prevailing thread */ protected ExposedNodeLinkedList prevailingQueue; @@ -98,7 +105,15 @@ public Map acquireLocksForClone(Object objectForClone, ClassDescriptor descripto toWaitOn.wait();// wait for lock on object to be released } } catch (InterruptedException ex) { - // Ignore exception thread should continue. + //https://jira.site1.hyperwallet.local/browse/HW-53073 + //Custom change to allow thread interruptions for bad threads stuck in org.eclipse.persistence.internal.helper.WriteLockManager.acquireLocksForClone pattern + if (isInterruptionEnabled()) { + logger.log(Level.SEVERE, + "EclipseLinkLockHandler has set interruption flag to TRUE. Allowing interrupts"); + throw ConcurrencyException.waitWasInterrupted(ex.getMessage()); + } + logger.log(Level.WARNING, + "EclipseLinkLockHandler has not set the interruption flag to TRUE. Will not interrupt"); } } Object waitObject = toWaitOn.getObject(); @@ -110,6 +125,7 @@ public Map acquireLocksForClone(Object objectForClone, ClassDescriptor descripto toWaitOn = acquireLockAndRelatedLocks(objectForClone, lockedObjects, refreshedObjects, cacheKey, descriptor, cloningSession); if ((toWaitOn != null) && ((++tries) > MAXTRIES)) { // If we've tried too many times abort. + logger.log(Level.WARNING, "Interruption done by EclipseLink Library."); throw ConcurrencyException.maxTriesLockOnCloneExceded(objectForClone); } } From fa2a3e57ac40508ccb1c4c9c9b5d1b54f4f6b8cd Mon Sep 17 00:00:00 2001 From: Josh Portner Date: Thu, 25 Feb 2021 16:29:03 -0800 Subject: [PATCH 2/2] imports --- .../eclipse/persistence/internal/helper/WriteLockManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/WriteLockManager.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/WriteLockManager.java index 4d9a05e7a44..86214ac8d7d 100644 --- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/WriteLockManager.java +++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/WriteLockManager.java @@ -26,6 +26,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; import org.eclipse.persistence.descriptors.ClassDescriptor; import org.eclipse.persistence.descriptors.FetchGroupManager; @@ -70,7 +72,7 @@ public class WriteLockManager { private static boolean isInterruptionEnabled() { String value = System.getProperty("interruptionEnabled"); - return parseBoolean(value); + return Boolean.parseBoolean(value); } /* This attribute stores the list of threads that have had a problem acquiring locks */