actviti7 的 asyncExecutor
2023-07-03 09:38:03 0 举报
AI智能生成
actviti7 的 asyncExecutor
作者其他创作
大纲/内容
1. 初始化
引入 spring-activiti 的依赖后, 由 <font color="#ff0000">springProcessEngineConfiguration</font> 配置类来初始化
1. 真正的实现类, <font color="#ff0000">SpringAsyncExecutor</font>
如果没有 spring-activiti 的依赖后, 真正的实现类 <font color="#ff0000">DefaultAsyncJobExecutor</font>
2. 启动
1. 配置 org.activiti.engine.impl.asyncexecutor.DefaultAsyncJobExecutor#applyConfig
如果引入 spring-activiti 依赖之后,线程池参数无用。
2. 配置
1.
2. ProcessEngineConfigurationImpl#initAsyncExecutor
如果没有指定,会创建一个默认的
如果引入 spring-activiti 依赖之后, 默认就是 <font color="#ff0000">SpringAsyncExecutor</font>
3. 启动
1. new ProcessEngineImpl()
asyncExecutor.start()
3. 定时任务
1. AcquireTimerJobsRunnable
1. new AcquireTimerJobsCmd(asyncExecutor)
1. 获取 timerJob 列表
1. 每次查询记录条数为 (maxAsyncJobsDuePerAcquisition = 1)
2. mybatis 对应 sql 的 id: <font color="#ff0000">selectTimerJobsToExecute</font>
2. 对每个 timeerJob 进行 lockJob
1. 锁定任务的时间 (asyncJobLockTimeInMillis = 5 * 60 * 1000)
2. 对 timeJob 任务添加 <font color="#ff0000">[lockOwner]</font> 和 <font color="#ff0000">[lockExpirationTime]</font>
2. jobManager.moveTimerJobToExecutableJob(job)
1. 移动 timerJob 到 job
1. 锁定任务时间 ( timerLockTimeInMillis = 5 * 60 * 1000)
2. 插入成功,删除原有的 timerJob
3.添加 AsyncJobAddedNotification 回调
代码位置 org.activiti.engine.impl.jobexecutor.AsyncJobAddedNotification#closed
2. ResetExpiredJobsRunnable
1. new FindExpiredJobsCmd(asyncExecutor.getResetExpiredJobsPageSize())
查找过期的 job
1. 每次查询记录条数为 ( resetExpiredJobsPageSize = 3)
2. mybatis 对应的 sql 的 id: <font color="#ff0000">selectExpiredJobs</font>
2. new ResetExpiredJobsCmd(expiredJobIds)
重置过期的 job
1. 查询到 job
2. 对每个job 都删除, 重新创建一个新的 job
3. 新的 job, lockExpirationTime 和 lockOwner 都为null
3. AcquireAsyncJobsDueRunnable
1. new AcquireJobsCmd(asyncExecutor)
1. 获取 job 列表
1. 每次查询记录条数为 ( <font color="#ff0000">maxAsyncJobsDuePerAcquisition = 1</font> )
2. 查询 lockExpirationTime 为 null 的 数据
2. mybatis 对应的 sql 的 id: selectJobsToExecute
2. 对每个 job 进行 lockJob
1. 锁定 job 的时间 ( asyncJobLockTimeInMillis = 5 * 60 * 1000 )
2. 执行 job
4. executeTemporaryJobs()
1. 临时任务,可以在 初始化 ProcessEngineConfiguration 时 ,添加临时任务
asyncExecutor.executeAsyncJob(job)
ExecuteAsyncRunnable
0 条评论
下一页