Skip to content

Commit

Permalink
Merge pull request #1231 from e210/main
Browse files Browse the repository at this point in the history
Improve Singleton instantiation in SchedulerRepository
  • Loading branch information
jhouserizer authored Oct 30, 2024
2 parents d12b678 + a5e80ba commit 19e622c
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions quartz/src/main/java/org/quartz/impl/SchedulerRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,36 @@ public class SchedulerRepository {

private final HashMap<String, Scheduler> schedulers;

private static SchedulerRepository inst;

/*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
*
* Constructors.
*
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

private SchedulerRepository() {
schedulers = new HashMap<>();
}

private static class Holder {
private static final SchedulerRepository INSTANCE = new SchedulerRepository();
}
/*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
*
* Interface.
*
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

public static synchronized SchedulerRepository getInstance() {
if (inst == null) {
inst = new SchedulerRepository();
}

return inst;
return Holder.INSTANCE;
}

public synchronized void bind(Scheduler sched) throws SchedulerException {

if ((Scheduler) schedulers.get(sched.getSchedulerName()) != null) {
if (schedulers.get(sched.getSchedulerName()) != null) {
throw new SchedulerException("Scheduler with name '"
+ sched.getSchedulerName() + "' already exists.");
}
Expand Down

0 comments on commit 19e622c

Please sign in to comment.