Java RMI object static and not static field? -
so have code:
public class remoteimpl extends unicastremoteobject implements testremote { private static final long serialversionuid = 1l; private static int counter = 0; private int localizedcounter = 0; protected remoteimpl() throws remoteexception { super(); } @override public int getmeglobalcounter() throws remoteexception { counter++; return counter; } @override public int getmelocalizedcounter() throws remoteexception { localizedcounter++; return localizedcounter; } } and client trying:
public class testclient { public static void main(string[] args) throws exception { registry registry = locateregistry.getregistry("localhost", constant.rmi_port); testremote remote = (testremote) registry.lookup(constant.rmi_id); system.out.println("global counter:" + remote.getmeglobalcounter()); system.out.println("localized counter:" + remote.getmelocalizedcounter()); } } after running code 2 times expecting see:
global counter:3 localized counter:1 however see that
localized counter:3 so why localized counter not reset everytime invoke method? not getting new object everytime?
am not getting new object every time?
no aren't. you're getting same instance bound registry. rmi doesn't create remote objects willy-nilly.
Comments
Post a Comment