convert tasks in delayed executor to utilize Timer

This commit is contained in:
Aria 2023-02-28 08:33:28 -07:00
parent d94bb8e775
commit 902cca2f42
3 changed files with 22 additions and 9 deletions

View file

@ -44,11 +44,24 @@ public class DelayedExecutorService {
public List<DelayedExecution> EXECUTORS = new ArrayList<>();
public void schedule(Runnable run, int seconds)
public void schedule(final Runnable run, int seconds)
{
long unix = Instant.now().getEpochSecond()+ (seconds);
DelayedExecution exe = new DelayedExecution(run,unix);
EXECUTORS.add(exe);
//long unix = Instant.now().getEpochSecond()+ (seconds);
TimerTask task = new TimerTask() {
@Override
public void run()
{
run.run();
}
};
repeater.schedule(task, seconds*1000L);
//DelayedExecution exe = new DelayedExecution(run,unix);
//EXECUTORS.add(exe);
}
private static void stopRepeatingThread()
{
repeater.cancel();
}
public void onTick()
@ -56,10 +69,10 @@ public class DelayedExecutorService {
if(!LibZontreck.ALIVE)
{
LibZontreck.LOGGER.info("Tearing down delayed executor service");
DelayedExecutorService.stopRepeatingThread();
return;
}
Iterator<DelayedExecution> it = EXECUTORS.iterator();
/*Iterator<DelayedExecution> it = EXECUTORS.iterator();
while(it.hasNext())
{
DelayedExecution e = it.next();
@ -70,7 +83,7 @@ public class DelayedExecutorService {
tx.setName("DelayedExecutorTask-"+String.valueOf(DelayedExecutorService.getNext()));
tx.start();
}
}
}*/
}
public static int getNext()

View file

@ -19,7 +19,7 @@ modId="libzontreck" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build
version="1.0.5.0228230758" #mandatory
version="1.0.5.0228230829" #mandatory
# A display name for the mod
displayName="LibZontreck" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/