activiti 修改定时器的执行时间
来源:互联网 发布:chrome 程序员插件 编辑:程序博客网 时间:2024/06/05 06:11
在使用activiti5.19过程中,有一个应用场景需要在流程实例启动后,对定时器的执行时间进行修改,但是activiti本身并没有提供现成的api进行操作,需要自己进行处理,处理思路是通过自己实现Command的接口,使用DbSqlSession,来执行update操作,具体操作如下:
1 创建一个修改定时器的命令,实现Command接口,泛型为TimerEntity,表示该命令执行对TimerEntity(对应act_ru_job表)的操作。在execute方法中,获取到DbSqlSession,继而得到具体执行的statement,通过调用sqlSession的udpate方法,执行更新。
private final class UpdateTimerCommand implements Command<TimerEntity> { private final TimerEntity timerEntity; public UpdateTimerCommand(TimerEntity timerEntity) { this.timerEntity = timerEntity; } @Override public TimerEntity execute(CommandContext commandContext) { DbSqlSession dbsqlSession = commandContext.getDbSqlSession(); String statement = dbsqlSession.getDbSqlSessionFactory() .getUpdateStatement(timerEntity); dbsqlSession.getSqlSession().update(statement, timerEntity); return timerEntity; } }
2 通过runtimeService获取到命令执行器 CommandExecutor,执行定时器修改命令
public void executeUpdate(TimerEntity timerEntity){ RuntimeServiceImpl rsi = (RuntimeServiceImpl)runtimeService; CommandExecutor commandExecutor = rsi.getCommandExecutor(); commandExecutor.execute(new UpdateTimerCommand(timerEntity)); }
3 设置定时器任务新的执行时间
public void modifyDuedate(Job job,Date duedate){ if (job != null) { if (job instanceof TimerEntity) { TimerEntity timer = (TimerEntity) job; timer.setDuedate(duedate); executeUpdate(timer); } } }
完整代码
import org.activiti.engine.ManagementService;import org.activiti.engine.RuntimeService;import org.activiti.engine.impl.RuntimeServiceImpl;import org.activiti.engine.impl.db.DbSqlSession;import org.activiti.engine.impl.interceptor.Command;import org.activiti.engine.impl.interceptor.CommandContext;import org.activiti.engine.impl.interceptor.CommandExecutor;import org.activiti.engine.impl.persistence.entity.TimerEntity;import org.activiti.engine.runtime.Job;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;import java.util.Date;/** * Created by ct on 2016/10/23 0023. */@Componentpublic class UpdateTimerService { @Autowired private RuntimeService runtimeService; public void executeUpdate(TimerEntity timerEntity){ RuntimeServiceImpl rsi = (RuntimeServiceImpl)runtimeService; CommandExecutor commandExecutor = rsi.getCommandExecutor(); commandExecutor.execute(new UpdateTimerCommand(timerEntity)); } public void modifyDuedate(Job job,Date duedate){ if (job != null) { if (job instanceof TimerEntity) { TimerEntity timer = (TimerEntity) job; timer.setDuedate(duedate); executeUpdate(timer); } } } private final class UpdateTimerCommand implements Command<TimerEntity> { private final TimerEntity timerEntity; public UpdateTimerCommand(TimerEntity timerEntity) { this.timerEntity = timerEntity; } @Override public TimerEntity execute(CommandContext commandContext) { DbSqlSession dbsqlSession = commandContext.getDbSqlSession(); String statement = dbsqlSession.getDbSqlSessionFactory() .getUpdateStatement(timerEntity); dbsqlSession.getSqlSession().update(statement, timerEntity); return timerEntity; } }}
0 0
- activiti 修改定时器的执行时间
- Quartz 定时器动态修改执行时间修改后出现立即执行情况
- activiti定时器的时间用法
- 计算一个程序的执行时间和定时器
- Quartz 定时器动态创建任务和修改执行时间修改后出现立即执行情况
- Oracle job 定时器的执行时间间隔 学习汇总
- Oracle job定时器的执行时间间隔学习汇总
- 为什么Linux内核无法保证动态定时器的执行时间
- Oracle job定时器的执行时间间隔学习汇总
- phpMyadmin最大执行时间修改
- 皮带线定时器的修改
- CCS中使用DSP定时器的计时程序,可以精确计算某一段程序的执行时间
- Activiti修改流程定义
- activiti工作流源码修改
- 创建定时器,并修改定时器的线程级别
- Activiti实现流程定义的控制与修改
- 对spring任务定时器的动态修改
- 对spring任务定时器的动态修改
- SCAU10690 分面包
- 欢迎使用CSDN-markdown编辑器
- SpringInAction:在Spring中应用切面
- TCP协议详解
- android四大组件---BroadcastReceiver应用详解
- activiti 修改定时器的执行时间
- python量化分析—对海龟交易法则的验证
- Git学习笔记
- ios 3D引擎 SceneKit 开发(8) --SCNShape 的使用
- [DP]poj3176 Cow Bowling
- linux下vim命令详解
- Canada Cup 2016
- Android - BGAQRCode 扫描二维码
- LeetCode 419 Battleships in a Board (DFS 或 模拟)