Skip to content

Commit

Permalink
Log unterminated thread stacktraces on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
NickNackGus authored Oct 17, 2024
1 parent a3f3176 commit 36cc112
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/playmonumenta/structures/StructuresPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitWorker;

public class StructuresPlugin extends JavaPlugin {
public @Nullable RespawnManager mRespawnManager = null;
Expand Down Expand Up @@ -82,6 +83,19 @@ public void onDisable() {
mRespawnManager = null;
}

// Log any async threads that haven't finished yet
for (BukkitWorker worker : Bukkit.getScheduler().getActiveWorkers()) {
if (!worker.getOwner().equals(this)) {
continue;
}

Thread thread = worker.getThread();
StringBuilder builder = new StringBuilder("Unterminated thread stacktrace:");
for (StackTraceElement traceElement : thread.getStackTrace()) {
builder.append("\n\tat ").append(traceElement);
}
getLogger().severe(builder.toString());
}
// Cancel any remaining tasks
getServer().getScheduler().cancelTasks(this);

Expand Down

0 comments on commit 36cc112

Please sign in to comment.