RMI Server java application terminates
843793May 11 2006 — edited May 12 2006Please help on this one. Very strange. I have a RMI server that terminates on its own after long time left inactive. The server works perfectly with the clients .... but if I leave (overnight for instance) the server running it terminates after awhile. I have no idea why it does that ... This is the code (very simple) I use if it can help:
public class TCServer {
private static final Properties tcProperties = new Properties();
private TCServerManager rmiServer = null;
public TCServer() {
// load the properties
try {
tcProperties.load(Resources.getResourceInputStream("server.properties"));
} catch (Exception ex) {
ex.printStackTrace();
}
// start the rmi server
rmiServer = new TCServerManager(getTCProperty("driver", ""),
getTCProperty("alias", ""),
getTCProperty("host", ""),
getTCProperty("port", ""),
getTCProperty("db", ""),
getTCProperty("user", ""),
getTCProperty("pswd", ""));
}
public static String getTCProperty(String name, String defaultValue) {
return tcProperties.getProperty(name, defaultValue);
}
public static void main (String[] args) {
new TCServer();
Runtime.getRuntime().addShutdownHook(new FinalOperations());
}
private static class FinalOperations extends Thread {
public void run() {
System.out.println("The server is shutting down!!!! - Notify all clients ...");
}
}
}
public class TCServerManager {
private static final String SERVER_NAME = "myservice";
private TCServerImplementation implementation = null;
private DBConnection dbConn = null;
public TCServerManager(String driver,
String alias,
String host,
String port,
String db,
String user,
String pswd) {
try {
Registry registry = java.rmi.registry.LocateRegistry.createRegistry(1099);
System.setSecurityManager(new RMISecurityManager());
dbConn = new DBConnection(driver, alias, host, port, db, user, pswd);
implementation = new TCServerImplementation(dbConn);
Naming.rebind(SERVER_NAME, implementation);
System.out.println("Server ready...");
} catch (MalformedURLException ex1) {
System.err.println("ERROR: The name is not an appropriate formatted URL!");
ex1.printStackTrace();
}
catch (RemoteException ex2) {
System.err.println("ERROR: Cannot contact the rmi registry!");
ex2.printStackTrace();
}
}
}
Any idea what is going on ... It seems like there is some sort of timeout that when the server stay unused for long time it exits..
Please help ... I need to solve this issue, otherwise I have a server that doesn't provide a reliable service.
Thanks.