java - Why is my RMI server dying after 20 hours -


i have problem rmi application. after 20 hours (+/- few hrs) clients can no longer connect. in first 20 hours of server's lifetime though can make many connections want. suspected problem rmi remote object being garbacge collected there no references pointing it, can rule out 2 reasons:

  1. i forced jvm running server gc using jconsole , clients can still connect
  2. i hold reference server in main method, not exit , rmi registry , stub members of server class.

my server creates rmi registry on port 1099 , gets exported unicastremoteobject on port 5099. when clients can no longer connect after 20 hours java.rmi.connectexception. clear server's java process still running , registry (running within process) still responding , returning remote object. exception thrown when call remote method on client side.

if "netstat -tulpn" on server machine can see java process listening on port 5099 initially, once 20 hour bug kicks in server no longer listening on port. think can rule out firewall issues well, have disabled server firewall testing. below simplified version of code. ideas of what's going on there , how make server live indefintely appreciated. cheers!

import java.rmi.remoteexception; import java.rmi.registry.locateregistry; import java.rmi.registry.registry; import java.rmi.server.unicastremoteobject;  public class myrmiserver implements myrmiinterface {  private myrmiinterface stub;  private registry registry;   public static void main(string[] args)  {     myrmiserver server = new myrmiserver();      server.startrmiservices();      // sleep, don't let main thread die, otherwise might loose our ref       // rmi stub and/or registry     while (true)      {         try {             thread.sleep(5000);         } catch (interruptedexception e) {             e.printstacktrace();         }     }  }  private void startrmiservices() {      try {         // set security manager         if (system.getsecuritymanager() == null) {             system.setsecuritymanager(new securitymanager());         }          // create stub         stub = (myrmiinterface) unicastremoteobject.exportobject(this,5099);          // bind remote object's stub in registry         registry = locateregistry.createregistry(1099);         registry.rebind("myserver", stub);          system.out.println("rmi ready");      } catch (remoteexception e) {         e.printstacktrace();     }  }  @override public synchronized int remotecall(int x) throws remoteexception {     return x+1; }    } 

the loop in main() isn't best way prevent objects being dgc'd , gc'd. make stub , registry static.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -