diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/ConcurrencyManager.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/ConcurrencyManager.java index 672ff0d2d8a..dbaa3705b1c 100644 --- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/ConcurrencyManager.java +++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/helper/ConcurrencyManager.java @@ -1,5 +1,6 @@ /* * Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021 IBM Corporation. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -81,6 +82,11 @@ public class ConcurrencyManager implements Serializable { private static final Set THREADS_WAITING_TO_RELEASE_DEFERRED_LOCKS = new HashSet<>(); private static final Map THREADS_WAITING_TO_RELEASE_DEFERRED_LOCKS_BUILD_OBJECT_COMPLETE_GOES_NOWHERE = new ConcurrentHashMap<>(); + private static final String ACQUIRE_METHOD_NAME = ConcurrencyManager.class.getName() + ".acquire(...)"; + private static final String ACQUIRE_READ_LOCK_METHOD_NAME = ConcurrencyManager.class.getName() + ".acquireReadLock(...)"; + private static final String ACQUIRE_WITH_WAIT_METHOD_NAME = ConcurrencyManager.class.getName() + ".acquireWithWait(...)"; + private static final String ACQUIRE_DEFERRED_LOCK_METHOD_NAME = ConcurrencyManager.class.getName() + ".acquireDeferredLock(...)"; + /** * Initialize the newly allocated instance of this class. * Set the depth to zero. @@ -118,8 +124,7 @@ public synchronized void acquire(boolean forMerge) throws ConcurrencyException { // is just storing debug metadata that we can use when we detect the system is frozen in a dead lock final boolean currentThreadWillEnterTheWhileWait = ((this.activeThread != null) || (this.numberOfReaders.get() > 0)) && (this.activeThread != currentThread); if(currentThreadWillEnterTheWhileWait) { - StackTraceElement stackTraceElement = currentThread.getStackTrace()[1]; - putThreadAsWaitingToAcquireLockForWriting(currentThread, stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + "(...)"); + putThreadAsWaitingToAcquireLockForWriting(currentThread, ACQUIRE_METHOD_NAME); } while (((this.activeThread != null) || (this.numberOfReaders.get() > 0)) && (this.activeThread != Thread.currentThread())) { // This must be in a while as multiple threads may be released, or another thread may rush the acquire after one is released. @@ -197,8 +202,7 @@ public synchronized boolean acquireWithWait(boolean forMerge, int wait) throws C return true; } else { try { - StackTraceElement stackTraceElement = currentThread.getStackTrace()[1]; - putThreadAsWaitingToAcquireLockForWriting(currentThread, stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + "(...)"); + putThreadAsWaitingToAcquireLockForWriting(currentThread, ACQUIRE_WITH_WAIT_METHOD_NAME); wait(wait); } catch (InterruptedException e) { return false; @@ -246,8 +250,7 @@ public void acquireDeferredLock() throws ConcurrencyException { final long whileStartTimeMillis = System.currentTimeMillis(); final boolean currentThreadWillEnterTheWhileWait = this.numberOfReaders.get() != 0; if(currentThreadWillEnterTheWhileWait) { - StackTraceElement stackTraceElement = currentThread.getStackTrace()[1]; - putThreadAsWaitingToAcquireLockForWriting(currentThread, stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + "(...)"); + putThreadAsWaitingToAcquireLockForWriting(currentThread, ACQUIRE_DEFERRED_LOCK_METHOD_NAME); } while (this.numberOfReaders.get() != 0) { // There are readers of this object, wait until they are done before determining if @@ -323,8 +326,7 @@ public synchronized void acquireReadLock() throws ConcurrencyException { ReadLockManager readLockManager = getReadLockManager(currentThread); final boolean currentThreadWillEnterTheWhileWait = (this.activeThread != null) && (this.activeThread != currentThread); if (currentThreadWillEnterTheWhileWait) { - StackTraceElement stackTraceElement = currentThread.getStackTrace()[1]; - putThreadAsWaitingToAcquireLockForReading(currentThread, stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + "(...)"); + putThreadAsWaitingToAcquireLockForReading(currentThread, ACQUIRE_READ_LOCK_METHOD_NAME); } // Cannot check for starving writers as will lead to deadlocks. while ((this.activeThread != null) && (this.activeThread != Thread.currentThread())) {