Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW-53073: Allow Thread Interruption for WriteLockManager #2

Open
wants to merge 2 commits into
base: 2.7.6_branch
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}
Expand Down