Skip to content

Commit

Permalink
[JBPM-10088] Some test failed
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Nov 23, 2023
1 parent 5e2aed8 commit 459a47a
Showing 1 changed file with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public GlobalJpaTimerJobInstance(Job job, JobContext ctx, Trigger trigger,
@Override
public Void call() throws Exception {
AsyncExecutionMarker.markAsync();
ExecutableRunner<?> runner = null;
ExecutableRunner runner = null;
TransactionManager jtaTm = null;
boolean success = false;
try {
Expand All @@ -88,16 +88,16 @@ public Void call() throws Exception {
success = true;
return null;
} catch( Exception e ) {
logger.error("Exception executing timer", e);
e.printStackTrace();
success = false;
throw e;
} finally {
AsyncExecutionMarker.reset();
if (runner != null && runner instanceof DisposableCommandService) {
if (allowedToDispose(((DisposableCommandService) runner))) {
logger.debug("Allowed to dispose command service from global timer job instance");
((DisposableCommandService) runner).dispose();
}
if (runner != null && runner instanceof DisposableCommandService) {
if (allowedToDispose(((DisposableCommandService) runner).getEnvironment())) {
logger.debug("Allowed to dispose command service from global timer job instance");
((DisposableCommandService) runner).dispose();
}
}
closeTansactionIfNeeded(jtaTm, success);
}
Expand All @@ -123,11 +123,7 @@ public String toString() {
return "GlobalJpaTimerJobInstance [timerServiceId=" + timerServiceId
+ ", getJobHandle()=" + getJobHandle() + "]";
}

private boolean allowedToDispose(DisposableCommandService disposableCommandService) {
return !disposableCommandService.isDisposed() && allowedToDispose (disposableCommandService.getEnvironment());
}


protected boolean allowedToDispose(Environment environment) {
if (hasEnvironmentEntry(environment, "IS_JTA_TRANSACTION", false)) {
return true;
Expand Down Expand Up @@ -159,18 +155,23 @@ protected boolean hasEnvironmentEntry(Environment environment, String name, Obje
}

protected TransactionManager startTxIfNeeded(Environment environment) {
try {
boolean isTimerCMT = hasEnvironmentEntry(environment, "IS_TIMER_CMT", true);
logger.debug ("Timer CMT value is {}", isTimerCMT);
if (!isTimerCMT) {
TransactionManager tm = TransactionManagerFactory.get().newTransactionManager();
if (tm.begin()) {
return tm;
}
}

try {
if (hasEnvironmentEntry(environment, "IS_TIMER_CMT", true)) {
return null;
}
if (environment.get(EnvironmentName.TRANSACTION_MANAGER) instanceof ContainerManagedTransactionManager) {
TransactionManager tm = TransactionManagerFactory.get().newTransactionManager();

if (tm.begin()) {
return tm;
}
}

} catch (Exception e) {
logger.debug("Unable to optionally start transaction due to {}", e.getMessage(), e);
}

return null;
}

Expand Down

0 comments on commit 459a47a

Please sign in to comment.