I have the following shutdown hook in the main method of my Server class:
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
if (open) {
open = false;
//log out all players
System.out.println("Logging out all players...");
Iterator playerIterator = playerList.values().iterator();
while (playerIterator.hasNext()) {
Player p = (Player) playerIterator.next();
playerIterator.remove();
p.logout("The server has been shut down.");
}
//save the World
System.out.println("Saving world...");
try {
String worldFile = Server.path.concat("/worlds/"+worldName);
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(worldFile));
out.writeObject(world);
} catch (FileNotFoundException fe) {
System.out.println("World \"" + worldName + "\" couldn't be saved properly - world file not found.");
fe.printStackTrace();
} catch (IOException ioe) {
System.out.println("I/O error while attempting to save world \"" + worldName + "\".");
ioe.printStackTrace();
}
//close Server socket
try {
serverSocket.close();
System.out.println(worldName + " is now closed.");
} catch (IOException ioe) {
System.out.println("Failed to close ServerSocket.");
ioe.printStackTrace();
}
}
}
});
When I stop the server (by pressing Ctrl+c), the shutdown hook does everything it's supposed to do (it works perfectly), but I get the following message and the server won't finish shutting down (I have to press Ctrl+c again):
The system cannot find message text for message number 0x237b in the message file for Application.
I don't think it used to do this before I updated to Java 7! Any ideas why it might be doing this?
Found the answer at: http://social.technet.microsoft.com/Forums/windows/en-US/2d506b96-e856-4752-90af-4f8194bb0040/windows-7-command-prompt-message-errors-cmdexe?forum=w7itprogeneral