Do something on crash.

Discussion in 'Plugin Development' started by davejavu, Jan 24, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    davejavu

    Wondering, how would I execute some code when/if a server crashes?
     
  2. Offline

    tommycake50

    Runtime.getRuntime().addShutdownHook(Thread hook)

    that will be called when the java virtual machine shuts down.
    BUT you cant call any bukkit code it has to be pure java that's only on the thread you pass in.
     
  3. Offline

    davejavu

    Thanks :)
     
  4. Offline

    tommycake50

    not 100% sure it will fire in a crash tho...
     
  5. Offline

    camyono

    If the jvm crashes it wont work too... ( OutOfMemory etc... )

    davejavu
    If you cant catch it ( by try/catch ) you wont be able to catch it with java.

    So it is your work to write code well so it won't fail and cause jvm crashes. But i dont think the jvm will fail after nearly 20 years of production-level JREs and when its very rare.

    If it should happen you can write a daemon/cron / or any restart thread which will listen for this process ( it needs to be in a OS native language/script / no java ) - to restart your server.

    There are flags which can be set before starting get informations about a core dump etc.... like -XX:HeapDumpPath=/path/to/it & -XX:+HeapDump

    So this may cause crashes:

    - Native code ( JNI )
    - JDBC
    - OutOfMemory etc..
    - Optimaztion / Performance Packs / Tools
    - Libraries of the JVM itself could crash
    - Threads which will have a to high threshold of using the cpu

    I often heard of crashes with -Djava.library.path using wrong libs ( native libs )

    If you want to get information from coredump files you can use:
    Windows ( iam not sure if there where changes because i dont use it since 4 years ): DrWatson32.exe // or something like that
    Linux: pmap / isstack
    Mac: idk

    I hope this helps. Ask again if you need more information.
     
  6. Offline

    tommycake50

    thanks for the info!
     
Thread Status:
Not open for further replies.

Share This Page