I’m wondering how to avoid getting this exception when I use an MBean with JConsole to remotely execute a shutdown, which calls System.exit(1). I’ve verified I get no exception when shutdown is not called so everything else is set up right. Error is:
Problem invoking shutdown: java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is: java.io.EOFException
Which certainly makes sense! I just don’t want this to be an error condition.
This is expected. I assume that your JMX operation is what initiated the
System.exit(1)? It means that Jconsole was waiting for a response from the server and none was sent before the socket was closed. Even calling avoidmethod via JMX waits for an acknowledgement so jconsole can say “Method successfully invoked”. Since the server is shutting down, it makes sense that you don’t get a response.If you want to avoid this you can fork a thread to sleep a bit and then issue the exit. Something like: