How do you crash a JVM?

前端 未结 27 1474
故里飘歌
故里飘歌 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:21

    If you want to pretend you have run out of memory you can do

    public static void main(String[] args) {
        throw new OutOfmemoryError();
    }
    

    I know a couple of way to cause the JVM dump an error file by calling native methods (ones which are built in), but its probably best you not know how to do this. ;)

提交回复
热议问题