public void launchJob(@Nullable JobListener jobListener) throws JobException { this.jobListener = jobListener; boolean isLaunched = false; this.runningMap.putIfAbsent(this.jobContext.getJobName(), false); try { if (this.runningMap.replace(this.jobContext.getJobName(), false, true)) { LOGGER.info ("Job {} will be executed, add into running map.", this.jobContext.getJobId()); isLaunched = true; super.launchJob(jobListener); } else { LOGGER.warn ("Job {} will not be executed because other jobs are still running.", this.jobContext.getJobId()); } } finally { if (isLaunched) { if (this.runningMap.replace(this.jobContext.getJobName(), true, false)) { LOGGER.info ("Job {} is done, remove from running map.", this.jobContext.getJobId()); } else { throw new IllegalStateException("A launched job should have running state equal to true in the running map."); } } } }
public void launchJob(@Nullable JobListener jobListener) throws JobException { this.jobListener = jobListener; boolean isLaunched = false; this.runningMap.putIfAbsent(this.jobContext.getJobName(), false); try { if (this.runningMap.replace(this.jobContext.getJobName(), false, true)) { LOGGER.info ("Job {} will be executed, add into running map.", this.jobContext.getJobId()); isLaunched = true; super.launchJob(jobListener); } else { LOGGER.warn ("Job {} will not be executed because other jobs are still running.", this.jobContext.getJobId()); } } finally { if (isLaunched) { if (this.runningMap.replace(this.jobContext.getJobName(), true, false)) { LOGGER.info ("Job {} is done, remove from running map.", this.jobContext.getJobId()); } else { throw new IllegalStateException("A launched job should have running state equal to true in the running map."); } } } }