bug #I4HZYN 使用When操作同一个Node时,会造成Tag标签的线程不安全

This commit is contained in:
bryan31
2021-12-09 13:17:03 +08:00
parent 108a08d709
commit 106d59c65d
2 changed files with 13 additions and 17 deletions

View File

@@ -34,7 +34,7 @@ import java.util.Map;
* 普通组件抽象类
* @author Bryan.Zhang
*/
public abstract class NodeComponent {
public abstract class NodeComponent{
private static final Logger LOG = LoggerFactory.getLogger(NodeComponent.class);
@@ -43,14 +43,14 @@ public abstract class NodeComponent {
@Autowired(required = false)
private MonitorBus monitorBus;
private final TransmittableThreadLocal<String> tagTL = new TransmittableThreadLocal<>();
private final TransmittableThreadLocal<Map<String, Executable>> condNodeMapTL = new TransmittableThreadLocal<>();
private String nodeId;
private String name;
private String tag;
private Map<String, Executable> condNodeMap;
private NodeTypeEnum type;
//这是自己的实例取代this
@@ -89,7 +89,7 @@ public abstract class NodeComponent {
if (this instanceof NodeCondComponent) {
String condNodeId = slot.getCondResult(this.getClass().getName());
if (StrUtil.isNotBlank(condNodeId)) {
Executable condExecutor = condNodeMap.get(condNodeId);
Executable condExecutor = this.condNodeMapTL.get().get(condNodeId);
if (ObjectUtil.isNotNull(condExecutor)) {
condExecutor.execute(slotIndexTL.get());
}
@@ -231,19 +231,15 @@ public abstract class NodeComponent {
this.retryForExceptions = retryForExceptions;
}
public String getTag() {
return tag;
public void setTag(String tag){
this.tagTL.set(tag);
}
public void setTag(String tag) {
this.tag = tag;
public String getTag(){
return this.tagTL.get();
}
public Map<String, Executable> getCondNodeMap() {
return condNodeMap;
}
public void setCondNodeMap(Map<String, Executable> condNodeMap) {
this.condNodeMap = condNodeMap;
public void setCondNodeMap(Map<String, Executable> condNodeMap){
this.condNodeMapTL.set(condNodeMap);
}
}

View File

@@ -9,6 +9,6 @@
</chain>
<chain name="chain3">
<when value="b[1],b[2],b[3]"/>
<when value="b[1],b[2],b[3],b"/>
</chain>
</flow>