Merge Task#scheduleForShutdown into Task#schedule

This commit is contained in:
Matthew 2021-08-23 19:37:10 +02:00 committed by Matt Worzala
parent 1c92414cad
commit 75964f87b4
2 changed files with 20 additions and 24 deletions

View File

@ -100,6 +100,15 @@ public class Task implements Runnable {
* Sets up the task for correct execution. * Sets up the task for correct execution.
*/ */
public void schedule() { public void schedule() {
if(this.shutdown) {
Int2ObjectMap<Task> shutdownTasks = this.schedulerManager.shutdownTasks;
synchronized (shutdownTasks) {
shutdownTasks.put(getId(), this);
}
if (owningExtension != null) {
this.schedulerManager.onScheduleShutdownFromExtension(owningExtension, this);
}
} else {
Int2ObjectMap<Task> tasks = this.schedulerManager.tasks; Int2ObjectMap<Task> tasks = this.schedulerManager.tasks;
synchronized (tasks) { synchronized (tasks) {
tasks.put(getId(), this); tasks.put(getId(), this);
@ -111,15 +120,6 @@ public class Task implements Runnable {
this.schedulerManager.getTimerExecutionService().schedule(this, this.delay, TimeUnit.MILLISECONDS) : this.schedulerManager.getTimerExecutionService().schedule(this, this.delay, TimeUnit.MILLISECONDS) :
this.schedulerManager.getTimerExecutionService().scheduleAtFixedRate(this, this.delay, this.repeat, TimeUnit.MILLISECONDS); this.schedulerManager.getTimerExecutionService().scheduleAtFixedRate(this, this.delay, this.repeat, TimeUnit.MILLISECONDS);
} }
public void scheduleForShutdown() {
Int2ObjectMap<Task> shutdownTasks = this.schedulerManager.shutdownTasks;
synchronized (shutdownTasks) {
shutdownTasks.put(getId(), this);
}
if (owningExtension != null) {
this.schedulerManager.onScheduleShutdownFromExtension(owningExtension, this);
}
} }
/** /**

View File

@ -162,11 +162,7 @@ public class TaskBuilder {
@NotNull @NotNull
public Task schedule() { public Task schedule() {
Task task = build(); Task task = build();
if (this.shutdown) {
task.scheduleForShutdown();
} else {
task.schedule(); task.schedule();
}
return task; return task;
} }
} }