Server will create a thread dump on a heartbeat death

This commit is contained in:
ceikry 2021-08-08 22:22:03 -05:00
parent f8950359a2
commit 2a1e082485

View file

@ -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.