From bb73b6c3f5f4fd79727d446f17cb287aa0cf164a Mon Sep 17 00:00:00 2001 From: Enrique Gonzalez Martinez Date: Tue, 5 Dec 2023 13:01:14 +0100 Subject: [PATCH] [private-bamoe-issues-1326] [DBACLD-109939] BBVA duplicate timer issue --- .../process/core/timer/impl/GlobalTimerService.java | 12 +++++++++++- .../jbpm/services/ejb/timer/EJBTimerScheduler.java | 3 ++- .../jbpm/services/ejb/timer/EjbSchedulerService.java | 7 ++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/jbpm-flow/src/main/java/org/jbpm/process/core/timer/impl/GlobalTimerService.java b/jbpm-flow/src/main/java/org/jbpm/process/core/timer/impl/GlobalTimerService.java index 2daa6b2cfd..4f2d58e707 100644 --- a/jbpm-flow/src/main/java/org/jbpm/process/core/timer/impl/GlobalTimerService.java +++ b/jbpm-flow/src/main/java/org/jbpm/process/core/timer/impl/GlobalTimerService.java @@ -338,10 +338,20 @@ public static class GlobalJobHandle extends DefaultJobHandle private static final long serialVersionUID = 510l; + private transient boolean valid; public GlobalJobHandle(long id) { super(id); + this.valid = true; } - + + public boolean isValid() { + return valid; + } + + public void setValid(boolean valid) { + this.valid = valid; + } + public Long getTimerId() { JobContext ctx = this.getTimerJobInstance().getJobContext(); if (ctx instanceof SelfRemovalJobContext) { diff --git a/jbpm-services/jbpm-services-ejb/jbpm-services-ejb-timer/src/main/java/org/jbpm/services/ejb/timer/EJBTimerScheduler.java b/jbpm-services/jbpm-services-ejb/jbpm-services-ejb-timer/src/main/java/org/jbpm/services/ejb/timer/EJBTimerScheduler.java index 10f7da7613..b262fe53bf 100644 --- a/jbpm-services/jbpm-services-ejb/jbpm-services-ejb-timer/src/main/java/org/jbpm/services/ejb/timer/EJBTimerScheduler.java +++ b/jbpm-services/jbpm-services-ejb/jbpm-services-ejb-timer/src/main/java/org/jbpm/services/ejb/timer/EJBTimerScheduler.java @@ -253,7 +253,8 @@ public void internalSchedule(TimerJobInstance timerJobInstance) { Timer timer = timerService.createSingleActionTimer(expirationTime, config); TimerHandle handle = timer.getHandle(); ((GlobalJpaTimerJobInstance) timerJobInstance).setTimerInfo(handle); - logger.debug("Timer scheduled {} on {} scheduler service", timerJobInstance); + String timerServiceId = ((EjbGlobalJobHandle) timerJobInstance.getJobHandle()).getDeploymentId(); + logger.debug("Timer scheduled {} on {} scheduler service", timerJobInstance, timerServiceId); ((GlobalJpaTimerJobInstance) timerJobInstance).setExternalTimerId(getPlatformTimerId(timer)); if (useLocalCache) { localCache.putIfAbsent(((EjbGlobalJobHandle) timerJobInstance.getJobHandle()).getUuid(), timerJobInstance); diff --git a/jbpm-services/jbpm-services-ejb/jbpm-services-ejb-timer/src/main/java/org/jbpm/services/ejb/timer/EjbSchedulerService.java b/jbpm-services/jbpm-services-ejb/jbpm-services-ejb-timer/src/main/java/org/jbpm/services/ejb/timer/EjbSchedulerService.java index 2ad481713a..2d19bb12dd 100644 --- a/jbpm-services/jbpm-services-ejb/jbpm-services-ejb-timer/src/main/java/org/jbpm/services/ejb/timer/EjbSchedulerService.java +++ b/jbpm-services/jbpm-services-ejb/jbpm-services-ejb-timer/src/main/java/org/jbpm/services/ejb/timer/EjbSchedulerService.java @@ -105,6 +105,7 @@ public boolean removeJob(JobHandle jobHandle) { // this situation needs to be avoided as it should not happen return false; } + ((GlobalJobHandle) jobHandle).setValid(false); JtaTransactionManager tm = (JtaTransactionManager) TransactionManagerFactory.get().newTransactionManager(); try { tm.registerTransactionSynchronization(new TransactionSynchronization() { @@ -117,9 +118,10 @@ public void afterCompletion(int status) { if (status == TransactionManager.STATUS_COMMITTED) { logger.debug("remove job {} after commited", jobHandle); scheduler.removeJob(jobHandle, ejbTimer); + } else { + ((GlobalJobHandle) jobHandle).setValid(true); } } - }); logger.debug("register tx to remove job {}", jobHandle); return true; @@ -257,8 +259,7 @@ public void setInterceptor(SchedulerServiceInterceptor interceptor) { @Override public boolean isValid(GlobalJobHandle jobHandle) { - - return true; + return jobHandle.isValid(); } protected String getJobName(JobContext ctx, long id) {