From 23cbf695a754991820d0daf4809a0c3809d1df8d Mon Sep 17 00:00:00 2001 From: Josh Portner Date: Wed, 20 Oct 2021 15:10:20 -0700 Subject: [PATCH] DTRUNWONE-184 Build eclipselink jar with thread interruption changes --- .../internal/helper/WriteLockManager.java | 20 ++++++++++++++++++- 1 file changed, 19 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..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; @@ -61,11 +63,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 Boolean.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 +107,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 +127,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); } }