diff --git a/Server/src/main/kotlin/rs09/Server.kt b/Server/src/main/kotlin/rs09/Server.kt index 13285503f..684a7b039 100644 --- a/Server/src/main/kotlin/rs09/Server.kt +++ b/Server/src/main/kotlin/rs09/Server.kt @@ -16,10 +16,14 @@ import rs09.game.system.config.ServerConfigParser import rs09.game.world.GameWorld import rs09.game.world.repository.Repository import java.io.File +import java.io.FileWriter +import java.lang.management.ManagementFactory +import java.lang.management.ThreadMXBean import java.net.BindException import java.util.* import kotlin.system.exitProcess + /** * The main class, for those that are unable to read the class' name. * @author Emperor @@ -108,6 +112,13 @@ object Server { while(running){ if(System.currentTimeMillis() - lastHeartbeat > 1800 && running){ SystemLogger.logErr("Triggering reboot due to heartbeat timeout") + SystemLogger.logErr("Creating thread dump...") + val dump = threadDump(true, true) + FileWriter("latestdump.txt").use { + it.write(dump) + it.flush() + it.close() + } exitProcess(0) } delay(625) @@ -140,6 +151,15 @@ object Server { return startTime } + private fun threadDump(lockedMonitors: Boolean, lockedSynchronizers: Boolean): String? { + val threadDump = StringBuffer(System.lineSeparator()) + val threadMXBean: ThreadMXBean = ManagementFactory.getThreadMXBean() + for (threadInfo in threadMXBean.dumpAllThreads(lockedMonitors, lockedSynchronizers)) { + threadDump.append(threadInfo.toString()) + } + return threadDump.toString() + } + /** * Sets the bastartTime.ZZ * @param startTime the startTime to set.