diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java index 6fb36bf1e..090d4080c 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/FlowExecutor.java @@ -398,6 +398,15 @@ public class FlowExecutor { } slot.setException(e); } finally { + try{ + if (ObjectUtil.isNotNull(chain)){ + chain.executeFinally(slotIndex); + } + }catch (Exception e){ + String errMsg = StrUtil.format("[{}]:an exception occurred during the finally Component execution in chain[{}]", slot.getRequestId(), chain.getChainName()); + LOG.error(errMsg, e); + } + if (!isInnerChain) { slot.printStep(); DataBus.releaseSlot(slotIndex); diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Chain.java b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Chain.java index c351945d4..88b4495b5 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Chain.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/entity/flow/Chain.java @@ -79,17 +79,6 @@ public class Chain implements Executable { if (CollUtil.isEmpty(conditionList)) { throw new FlowSystemException("no conditionList in this chain[" + chainName + "]"); } - try { - executeBody(slotIndex); - } finally { - executeFinally(slotIndex); - } - } - - // 执行主体的逻辑 - private void executeBody(Integer slotIndex) throws Exception { - //循环chain里包含的condition,每一个condition分四种类型:pre,then,when,finally - //这里conditionList其实已经是有序的,pre一定在最前面,finally一定在最后面 for (Condition condition : conditionList) { if (condition instanceof PreCondition){ for (Executable executableItem : condition.getNodeList()) { diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java index 2bfca78cf..5b1163d40 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/thread/ExecutorHelper.java @@ -14,6 +14,7 @@ import com.google.common.collect.Maps; import com.yomahub.liteflow.exception.ThreadExecutorServiceCreateException; import com.yomahub.liteflow.property.LiteflowConfig; import com.yomahub.liteflow.property.LiteflowConfigGetter; +import com.yomahub.liteflow.spi.holder.ContextAwareHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -123,7 +124,8 @@ public class ExecutorHelper { */ private ExecutorBuilder getExecutorBuilder(String threadExecutorClass) { try { - return (ExecutorBuilder) Class.forName(threadExecutorClass).newInstance(); + Class executorClass = (Class) Class.forName(threadExecutorClass); + return ContextAwareHolder.loadContextAware().registerBean(executorClass); } catch (Exception e) { LOG.error(e.getMessage(), e); throw new ThreadExecutorServiceCreateException(e.getMessage());