In one of my past interviews , someone asked me to write a code to crash the JVM. I said System.exit(). Is this correct? Are there any better answers?
clarification: I can include my piece of code during development and deploy. It is not that JVM is already running and I have to write a hacking code to crash the other JVM.
You can use the
Unsafeclass which is unsafe to use as you might guess.prints
I have used this to test when a change has been made to a file. I made the change and crashed the JVM to ensure something else wasn’t flushing or something later. Then I check I saw the update I expected.