fix autocloseable executors
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Beatrice Dellacà 2025-03-09 11:30:59 +01:00
parent f523e6cd92
commit 04d93dd7a5
3 changed files with 12 additions and 4 deletions

View File

@ -187,8 +187,10 @@ public class HidekoBot
// update slash commands (delayed)
final boolean finalForceUpdateCommands = forceUpdateCommands;
Executors.newSingleThreadScheduledExecutor().schedule(() -> // todo: try-with-resources
CommandUtil.updateSlashCommands(finalForceUpdateCommands), 1, TimeUnit.SECONDS);
try (ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor()) {
executor.schedule(() -> CommandUtil.updateSlashCommands(finalForceUpdateCommands),
1, TimeUnit.SECONDS);
}
// set the bot's status
jda.getPresence().setStatus(OnlineStatus.ONLINE);

View File

@ -10,6 +10,7 @@ import wtf.beatrice.hidekobot.HidekoBot;
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class DieCommand extends SlashCommandImpl
@ -28,7 +29,9 @@ public class DieCommand extends SlashCommandImpl
event.reply("Sorry, only the bot owner can run this command!").setEphemeral(true).queue();
} else {
event.reply("Going to sleep! Cya ✨").queue();
Executors.newSingleThreadScheduledExecutor().schedule(HidekoBot::shutdown, 3, TimeUnit.SECONDS);
try (ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor()) {
executor.schedule(HidekoBot::shutdown, 3, TimeUnit.SECONDS);
}
}
}
}

View File

@ -3,6 +3,7 @@ package wtf.beatrice.hidekobot.util;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@Deprecated(since = "0.5.16", forRemoval = true)
@ -49,7 +50,9 @@ public class Logger<T>
{
// create a new scheduled executor with an anonymous runnable...
//... after waiting <delay> seconds.
Executors.newSingleThreadScheduledExecutor().schedule(() -> log(message), delay, TimeUnit.SECONDS);
try (ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor()) {
executor.schedule(() -> log(message), delay, TimeUnit.SECONDS);
}
}