Trant
Trant

Reputation: 3609

How do I stop an RMI client?

I'm working on a project which is being revamped/modernized and it has a small RMI piece in it and unfortunately I never worked with RMI before.

One thing I am unable to figure out is why it keeps calling its custom SocketFactory constructor after I initially create a RMI client. It seems to happen like every 5 minutes I see output that the constructor is called even when there is no traffic between client and server.

So I guess there must be some way to end a client or clean it up somehow so it stops doing that but I dont know what it could be.

It sets up the RMI connection like so:

UnicastRemoteObject.exportObject(this);
TheServer rmiServer = (TheServer)Naming.lookup(s); // where s is some rmi:// url

So then I can access methods of the server and it can call methods on my client.

Once I am done with the connection, what should I do to cleanup and stop any threads for persisting?

I was checking out UnicastRemoteObject, maybe I need to use the method unexportObject?

But how is this custom SocketFactory getting called anyway, there are absolutely no references to its class name in my project, unless its some reflection in the background which is finding it by deriving the class name from the name of the client or something...

Upvotes: 0

Views: 917

Answers (1)

user207421
user207421

Reputation: 310985

You are seeing the effect of Distributed Garbage Collection. If you're finished with the stub, just release all local references and let it be locally garbage-collected. Then DGC will stop too, and all network activity to that remote object.

Upvotes: 1

Related Questions