Background:
I have written a java swing based client server application. The server is a spring container and has a bunch of services. The server-client communicate through serialized objects over sockets. The server spawns a new thread for each client session and maintains a map of the sessions over the period of communication.
I am adding a shutdown hook to the JVM
In my GUI, i have a “Stop Server” button which removes user sessions and cleans up .
Problem: This all works fine, but now I would like to let the clients known if the server is restarting or stopped. Any ideas on how to go about this?
Thanks.
You probably have a method to receive replies from the server. Let that method run in a separate thread and permanently waiting in a loop for messages from the server. When the server stops, the connection is closed, and the receiving method gets an exception.