fix autocloseable executors
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f523e6cd92
commit
04d93dd7a5
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user