Skip to content

Commit

Permalink
optimize the interface
Browse files Browse the repository at this point in the history
  • Loading branch information
lightClouds917 committed Mar 4, 2025
1 parent bf25be5 commit fbdb9c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Collection;
import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.seata.common.lock.ResourceLock;
Expand All @@ -39,19 +40,22 @@ public class LoopContextHolder {
private final Stack<Integer> forwardCounterStack = new Stack<>();
private Collection collection;
private final ResourceLock lock = new ResourceLock();
private static final ConcurrentHashMap<ProcessContext,ResourceLock> LOCK_MAP = new ConcurrentHashMap<>();

public static LoopContextHolder getCurrent(ProcessContext context, boolean forceCreate) {
LoopContextHolder loopContextHolder = (LoopContextHolder)context.getVariable(
DomainConstants.VAR_NAME_CURRENT_LOOP_CONTEXT_HOLDER);

if (null == loopContextHolder && forceCreate) {
try (ResourceLock ignored = context.getLock().obtain()) {
try (ResourceLock ignored = LOCK_MAP.computeIfAbsent(context, k -> new ResourceLock()).obtain()) {
loopContextHolder = (LoopContextHolder)context.getVariable(
DomainConstants.VAR_NAME_CURRENT_LOOP_CONTEXT_HOLDER);
if (null == loopContextHolder) {
loopContextHolder = new LoopContextHolder();
context.setVariable(DomainConstants.VAR_NAME_CURRENT_LOOP_CONTEXT_HOLDER, loopContextHolder);
}
} finally {
LOCK_MAP.remove(context);
}
}
return loopContextHolder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package org.apache.seata.saga.proctrl;

import org.apache.seata.common.lock.ResourceLock;

import java.util.Map;

/**
Expand Down Expand Up @@ -97,9 +95,4 @@ public interface ProcessContext {
*/
<T extends Instruction> T getInstruction(Class<T> clazz);

/**
* Gets get lock.
* @return the lock of the current process context
*/
ResourceLock getLock();
}

0 comments on commit fbdb9c1

Please sign in to comment.