Chapter 33. How to Crash Your JVM
Thomas Ronzon
There are so many new APIs, cool libraries, and must-try techniques you need to know that it can be hard to stay up-to-date.
But is this really all you need to know as a Java developer? What about the environment your software is running in? Couldn’t it be that a problem here could crash your software, and you wouldn’t even be able to understand or find that problem because it’s outside the world of libraries and code? Are you prepared to consider another perspective?
Here is a challenge: try to find ways to crash your Java Virtual Machine! (Or, at least, bring its normal execution to a sudden and unexpected stop.) The more ways you know, the better you understand your surroundings and appreciate what can go wrong with a running software system.
Here are a few to get you started:
-
Try to allocate as much memory as you can. RAM is not endless—if no more RAM can be allocated, your allocation will fail.
-
Try to write data to your hard disk until it is full. Same problem as with RAM: though bigger than RAM, disk space is not endless either.
-
Try to open as many files as you can. Do you know the maximum number of file descriptors for your environment?
-
Try to create as many threads as you can. On a Linux system, you can look at
/proc/sys/kernel/pid_maxand you will see how many processes may be running on your system. How many threads ...