How do you crash a JVM?

前端 未结 27 1378
故里飘歌
故里飘歌 2020-11-28 00:22

I was reading a book on programming skills wherein the author asks the interviewee, \"How do you crash a JVM?\" I thought that you could do so by writing an infinite for-loo

27条回答
  •  隐瞒了意图╮
    2020-11-28 01:05

    Does this count ?

    long pid = ProcessHandle.current().pid();
    try { Runtime.getRuntime().exec("kill -9 "+pid); } catch (Exception e) {}
    

    It only works for Linux and from Java 9.

    For some reason I don't get, ProcessHandle.current().destroyForcibly(); doesn't kill the JVM and throws java.lang.IllegalStateException with the message destroy of current process not allowed.

提交回复
热议问题