Skip to content

Commit

Permalink
Fallback to synchronised keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
krmahadevan committed Mar 1, 2024
1 parent cc23c7b commit 32d75e7
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 32d75e7

Please sign in to comment.