activiti 生命周期_activiti-5 核心之CommandContext 转

本文深入探讨了Activiti中的CommandContext,它是流程引擎内部执行的核心组件。CommandContext负责管理command的执行上下文,包括线程安全的副本栈、command、事务上下文、会话集合以及流程引擎配置。通过CommandInterceptor,CommandContext在创建后与command执行绑定,并在执行完毕后关闭,期间涉及会话提交、事务管理和异常处理。此外,还详细介绍了如何通过CommandContext获取不同类型的会话。
摘要由CSDN通过智能技术生成

众所周知,从以前的jbpm到现今的activiti,流程引擎的内部执行模式是command模式,不管是启动流程,

还是推动流程等等,

都采用了command的execute方法。

而command执行依赖于CommandContext,直译就是command的上下文,那么,

我们就来看看CommandContext里面的内容。

首先是CommandContext本身的类变量和实例变量:

private static Logger log = Logger.getLogger(CommandContext.class.getName());

private static final ThreadLocal> txContextStacks = new ThreadLocal>();

protected Command< ? > command;

protected TransactionContext transactionContext;

protected Map, Session> sessions = new HashMap, Session>();

protected Throwable exception = null;

protected ProcessEngineConfigurationImpl processEngineConfiguration;

其实从这个变量声明,我们就能够大致看出CommandContext的管辖范围,

首先是提供线程安全的副本栈txContextStacks,然后是在当前上下文执行的command,

事务上下文transactionContext,会话集合sessions ,流程引擎配置类processEngineConfiguration,

至于log和exception肯定就不用说了。当然,实际来说,transactionContext其实只是为session管理服务的,稍后可见。

为了避免线程冲突,每个command都在一个独立的commandContext中执行,如下:

public static void setCurrentCommandContext(CommandContext commandContext) {

getContextStack(true).push(commandContext);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值