More interesting points about RMI services

Source: Internet
Author: User

    • When you use Unicastremoteobject.export (Remote) to publish an object, a full GC is triggered.

    • You must manually manage the remote objects you publish, meaning that if there is no other client access, the objects/services you publish will be recycled and you will receive the following error

"NO SUCH OBJECT in TABLE."

Reference:

 Packagetest;Import StaticJava.util.concurrent.TimeUnit.MILLISECONDS;Import StaticJava.util.concurrent.TimeUnit.SECONDS;ImportJava.rmi.Remote;Importjava.rmi.RemoteException;ImportJava.rmi.registry.LocateRegistry;ImportJava.rmi.registry.Registry;ImportJava.rmi.server.UnicastRemoteObject;InterfaceRemoteoperationsextendsRemote {String remoteoperation ()throwsremoteexception;} Public Final classRmiImplementsremoteoperations {Private Static FinalString remote_name = remoteoperations.class. GetName (); Private Static FinalRemoteoperations classvariable =NewRMI (); Private Static BooleanHoldstrongreference =false; Private Static BooleanInvokegarbagecollector =true; Private Static intDelay = 0;  Public Static voidMainFinalString ... args)throwsException { for(FinalString Arg:args) {            if("-GC". Equals (ARG)) {Invokegarbagecollector=true; } Else if("-NOGC". Equals (ARG)) {Invokegarbagecollector=false; } Else if("-hold". Equals (ARG)) {holdstrongreference=true; } Else if("-release". Equals (ARG)) {holdstrongreference=false; } Else if(Arg.startswith ("-delay") ) {delay= Integer.parseint (arg.substring ("-delay". Length ())); } Else{System.err.println ("Usage:javac Rmitest.java && java rmitest [-GC] [-NOGC] [-hold] [-release] [-delay<seconds>]"); System.exit (1);        }} server (); if(invokegarbagecollector) {System.GC (); }        if(Delay > 0) {System.out.println ("Delaying" + delay + "seconds"); Final Longmilliseconds =Milliseconds.convert (delay, SECONDS);        Thread.Sleep (milliseconds);        } client (); System.exit (0);//Stop RMI Server thread} @Override PublicString remoteoperation () {return"Foo"; }    Private Static voidServer ()throwsException {//This reference are eligible for GC after this method returns        FinalRemoteoperations methodvariable =NewRMI (); FinalRemoteoperations tobestubbed = holdstrongreference?classvariable:methodvariable; FinalRemote Remote = Unicastremoteobject.exportobject (tobestubbed, 0); FinalRegistry Registry =locateregistry.createregistry (Registry.registry_port);    Registry.bind (Remote_name, REMOTE); }    Private Static voidClient ()throwsException {FinalRegistry Registry =Locateregistry.getregistry (); FinalRemote Remote =Registry.lookup (remote_name); FinalRemoteoperations stub = Remoteoperations.class. Cast (remote); FinalString message =stub.remoteoperation (); System.out.println ("Received:" +message); }}

Http://stackoverflow.com/questions/645208/java-rmi-nosuchobjectexception-no-such-object-in-table

More interesting points about RMI services

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.