优化流程提醒的加锁机制
FlowLong 起多个实例时,比如业务使用 Redis 加锁,应该只有一个实例进行流程提醒处理,其他实例应该立即返回,而不是线程阻塞
This commit is contained in:
parent
5401795039
commit
24d89e63ae
1
.gitignore
vendored
1
.gitignore
vendored
@ -20,3 +20,4 @@ bin/
|
||||
jdbc.properties
|
||||
|
||||
**/target/
|
||||
.flattened-pom.xml
|
||||
|
@ -16,9 +16,11 @@ package com.aizuda.bpm.engine.scheduling;
|
||||
public interface JobLock {
|
||||
|
||||
/**
|
||||
* 进入锁
|
||||
* 进入锁(获取锁),立即返回,不会阻塞等待锁
|
||||
*
|
||||
* @return true -> 获取到锁,false -> 未获取到锁
|
||||
*/
|
||||
void lock();
|
||||
boolean tryLock();
|
||||
|
||||
/**
|
||||
* 解除锁
|
||||
|
@ -33,8 +33,8 @@ public class LocalLock implements JobLock {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lock() {
|
||||
getLocalLock().lock();
|
||||
public boolean tryLock() {
|
||||
return getLocalLock().tryLock();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,6 +13,7 @@ import com.aizuda.bpm.engine.scheduling.RemindParam;
|
||||
import com.aizuda.bpm.engine.scheduling.TaskReminder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@ -27,6 +28,7 @@ import java.util.List;
|
||||
* @author noear
|
||||
* @since 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Setter
|
||||
@Getter
|
||||
public class SolonScheduler {
|
||||
@ -53,7 +55,10 @@ public class SolonScheduler {
|
||||
*/
|
||||
public void remind() {
|
||||
try {
|
||||
jobLock.lock();
|
||||
if (!jobLock.tryLock()) {
|
||||
log.info("[FlowLong] remind is already running, just return.");
|
||||
return;
|
||||
}
|
||||
TaskService taskService = context.getTaskService();
|
||||
List<FlwTask> flwTaskList = taskService.getTimeoutOrRemindTasks();
|
||||
if (ObjectUtils.isNotEmpty(flwTaskList)) {
|
||||
|
@ -10,6 +10,7 @@ import com.aizuda.bpm.engine.scheduling.RemindParam;
|
||||
import com.aizuda.bpm.engine.scheduling.TaskReminder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
@ -28,6 +29,7 @@ import java.util.List;
|
||||
* @author hubin
|
||||
* @since 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Getter
|
||||
@Setter
|
||||
public class SpringBootScheduler implements SchedulingConfigurer {
|
||||
@ -53,7 +55,10 @@ public class SpringBootScheduler implements SchedulingConfigurer {
|
||||
*/
|
||||
public void remind() {
|
||||
try {
|
||||
jobLock.lock();
|
||||
if (!jobLock.tryLock()) {
|
||||
log.info("[FlowLong] remind is already running, just return.");
|
||||
return;
|
||||
}
|
||||
TaskService taskService = context.getTaskService();
|
||||
List<FlwTask> flwTaskList = taskService.getTimeoutOrRemindTasks();
|
||||
if (ObjectUtils.isNotEmpty(flwTaskList)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user