RMI: How to Stop RMI Server Thread in a J2EE server?
Posted on 2006-05-23
I am running a servlet in a J2EE server - init() method of this servlet starts a RMI server (I start RMI server programatically using LocateRegistry.createRegistry() and then binding my Server object to this registry) and destroy() method of servlet is meant to clean up whatever RMI server has started/initialized. The problem is I am not able to figure out a way to stop the RMI server thread itself - this is persistent thread and unless this threads exits, destroy() of servlet doesn't exit. So I have two questions:
1. How to make sure that all threads that RMI server would have started to process client requests are through with their execution?
2. And how to stop main RMI server thread programatically?
This would be easier when we run RMI server from a command line, then putting System.exit(0) as the last call cleans up everything but in a J2EE server, it has become tricky.