How to suspend VM on startup when remote debugging your Java app
You want to do a remote debugging session on code that runs in the initial few seconds of your app being launched.
A problem that you can run into when attempting to do this is that since the code runs right in the beginning, the JVM may rush past it before you have had a chance to attach a debugger via Eclipse and set your break points.
The solution is to setup your JVM/debugging config so that it is set to suspend at startup.
A typical way to setup remote debugging is to use the following JVM argument in the code used to launch your application so that a debugger can later attach itself to port 8000.
Infact this is what Eclipse does when you launch an app in debug mode rather than normal mode. It adds this line in the JVM arguments used when launching your application.
Note the suspend=n. If that is set to y, the JVM will suspend on startup. It will wait for a debugger to attach to it and release it before it will proceed.
So using the suspend flag, our problem is solved. Happy debugging!