From 32d75e7441474ad20ee214c4c848ef968b31bdd5 Mon Sep 17 00:00:00 2001 From: Krishnan Mahadevan Date: Fri, 1 Mar 2024 12:48:39 +0530 Subject: [PATCH] Fallback to synchronised keyword --- .../org/testng/internal/invokers/TestMethodWorker.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/testng-core/src/main/java/org/testng/internal/invokers/TestMethodWorker.java b/testng-core/src/main/java/org/testng/internal/invokers/TestMethodWorker.java index de61ff59d..b729d68fa 100644 --- a/testng-core/src/main/java/org/testng/internal/invokers/TestMethodWorker.java +++ b/testng-core/src/main/java/org/testng/internal/invokers/TestMethodWorker.java @@ -102,8 +102,6 @@ public String toString() { return result.toString(); } - private static final KeyAwareAutoCloseableLock lock = new KeyAwareAutoCloseableLock(); - /** * Run all the ITestNGMethods passed in through the constructor. * @@ -121,9 +119,8 @@ && doesTaskHavePreRequisites() for (IMethodInstance testMethodInstance : m_methodInstances) { ITestNGMethod testMethod = testMethodInstance.getMethod(); - String key = Integer.toString(testMethod.getInstance().toString().hashCode()); - if (canInvokeBeforeClassMethods()) { - try (KeyAwareAutoCloseableLock.AutoReleasable ignore = lock.lockForObject(key)) { + synchronized (testMethod.getInstance()) { + if (canInvokeBeforeClassMethods()) { invokeBeforeClassMethods(testMethod.getTestClass(), testMethodInstance); } } @@ -132,7 +129,7 @@ && doesTaskHavePreRequisites() try { invokeTestMethods(testMethod, testMethodInstance.getInstance()); } finally { - try (KeyAwareAutoCloseableLock.AutoReleasable ignore = lock.lockForObject(key)) { + synchronized (testMethod.getInstance()) { invokeAfterClassMethods(testMethod.getTestClass(), testMethodInstance); } }