Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/main/java/org/audit4j/core/schedule/Schedulers.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public enum ExecutorType {
*/
public static Schedulers newDefault() {
createSingleton();
instance.increaseNoOfSchedullers();
Schedulers.increaseNoOfSchedullers();
instance.setCurrentScheduler(new ConcurrentTaskScheduler());
return instance;
}
Expand All @@ -67,7 +67,7 @@ public static Schedulers newDefault() {
*/
public static Schedulers newThreadPoolScheduler(int poolSize) {
createSingleton();
instance.increaseNoOfSchedullers();
Schedulers.increaseNoOfSchedullers();
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
CustomizableThreadFactory factory = new CustomizableThreadFactory();
scheduler.initializeExecutor(factory, new RejectedExecutionHandler() {
Expand Down Expand Up @@ -99,8 +99,8 @@ public static Schedulers stop(String schedulerId) {
throw new IllegalStateException("No schedulers match with given id.");
}
future.cancel(true);
instance.decreaseNoOfSchedullers();
instance.decreaseNoOfRunningSchedullers();
Schedulers.decreaseNoOfSchedullers();
Schedulers.decreaseNoOfRunningSchedullers();

return instance;
}
Expand All @@ -119,8 +119,8 @@ public static Schedulers stopAll() {
for (Entry<String, ScheduledFuture<?>> entry : instance.runningSchedullers.entrySet()) {
ScheduledFuture<?> future = entry.getValue();
future.cancel(true);
instance.decreaseNoOfSchedullers();
instance.decreaseNoOfRunningSchedullers();
Schedulers.decreaseNoOfSchedullers();
Schedulers.decreaseNoOfRunningSchedullers();
}

return instance;
Expand All @@ -138,9 +138,9 @@ public String schedule(TriggerTask task) {
throw new IllegalStateException("New scheduler should be crea");
}
ScheduledFuture<?> future = getCurrentScheduler().schedule(task.getRunnable(), task.getTrigger());
String id = getUUID();
String id = Schedulers.getUUID();
runningSchedullers.put(id, future);
increaseNoOfRunningSchedullers();
Schedulers.increaseNoOfRunningSchedullers();
setCurrentScheduler(null);
return id;
}
Expand All @@ -154,9 +154,9 @@ public String schedule(TriggerTask task) {
*/
public String schedule(Trigger trigger, Runnable task) {
ScheduledFuture<?> future = getCurrentScheduler().schedule(task, trigger);
String id = getUUID();
String id = Schedulers.getUUID();
runningSchedullers.put(id, future);
increaseNoOfRunningSchedullers();
Schedulers.increaseNoOfRunningSchedullers();
setCurrentScheduler(null);
return id;
}
Expand All @@ -173,28 +173,28 @@ public static TaskRegistrar taskRegistry() {
/**
* Increase no of schedullers.
*/
private synchronized void increaseNoOfSchedullers() {
private static synchronized void increaseNoOfSchedullers() {
noOfSchedullers++;
}

/**
* Increase no of running schedullers.
*/
private synchronized void increaseNoOfRunningSchedullers() {
private static synchronized void increaseNoOfRunningSchedullers() {
noOfRunningSchedullers++;
}

/**
* Decrease no of schedullers.
*/
private synchronized void decreaseNoOfSchedullers() {
private static synchronized void decreaseNoOfSchedullers() {
noOfSchedullers--;
}

/**
* Decrease no of running schedullers.
*/
private synchronized void decreaseNoOfRunningSchedullers() {
private static synchronized void decreaseNoOfRunningSchedullers() {
noOfRunningSchedullers--;
}

Expand All @@ -203,7 +203,7 @@ private synchronized void decreaseNoOfRunningSchedullers() {
*
* @return the uuid
*/
private synchronized String getUUID() {
private static synchronized String getUUID() {
return String.valueOf(UUID.randomUUID().getLeastSignificantBits());
}

Expand Down