convert tasks in delayed executor to utilize Timer
This commit is contained in:
parent
d94bb8e775
commit
902cca2f42
3 changed files with 22 additions and 9 deletions
|
@ -5,5 +5,5 @@ org.gradle.daemon=false
|
||||||
|
|
||||||
mc_version=1.18.2
|
mc_version=1.18.2
|
||||||
forge_version=40.2.1
|
forge_version=40.2.1
|
||||||
myversion=1.0.5.0228230758
|
myversion=1.0.5.0228230829
|
||||||
parchment_version=2022.11.06
|
parchment_version=2022.11.06
|
|
@ -44,11 +44,24 @@ public class DelayedExecutorService {
|
||||||
|
|
||||||
public List<DelayedExecution> EXECUTORS = new ArrayList<>();
|
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);
|
//long unix = Instant.now().getEpochSecond()+ (seconds);
|
||||||
DelayedExecution exe = new DelayedExecution(run,unix);
|
TimerTask task = new TimerTask() {
|
||||||
EXECUTORS.add(exe);
|
@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()
|
public void onTick()
|
||||||
|
@ -56,10 +69,10 @@ public class DelayedExecutorService {
|
||||||
if(!LibZontreck.ALIVE)
|
if(!LibZontreck.ALIVE)
|
||||||
{
|
{
|
||||||
LibZontreck.LOGGER.info("Tearing down delayed executor service");
|
LibZontreck.LOGGER.info("Tearing down delayed executor service");
|
||||||
|
DelayedExecutorService.stopRepeatingThread();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Iterator<DelayedExecution> it = EXECUTORS.iterator();
|
/*Iterator<DelayedExecution> it = EXECUTORS.iterator();
|
||||||
while(it.hasNext())
|
while(it.hasNext())
|
||||||
{
|
{
|
||||||
DelayedExecution e = it.next();
|
DelayedExecution e = it.next();
|
||||||
|
@ -70,7 +83,7 @@ public class DelayedExecutorService {
|
||||||
tx.setName("DelayedExecutorTask-"+String.valueOf(DelayedExecutorService.getNext()));
|
tx.setName("DelayedExecutorTask-"+String.valueOf(DelayedExecutorService.getNext()));
|
||||||
tx.start();
|
tx.start();
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getNext()
|
public static int getNext()
|
||||||
|
|
|
@ -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
|
# 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
|
# ${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
|
# 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
|
# A display name for the mod
|
||||||
displayName="LibZontreck" #mandatory
|
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/
|
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/
|
||||||
|
|
Reference in a new issue