I have one java process starting another java process with JMX support enabled in the following way
java -Dcom.sun.management.jmxremote.port=8088 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar app.jar
My problem is if the port 8088 is in use, the jvm of spawned process will throw BindException and the JVM will exit normally. There is no way for me to report back to the process that spawned process did not start because of bind exception. How can I catch/handle the BindException thrown by JVM so that the spawned process can do a System.exit(VALID_ERROR_CODE)? This exception happens even before any control is passed to the user code, so I guess it wouldn't be possible to handle it in the user code.
Any idea as how to handle this use case?