Creating a long-running RMI server

R

Rennie deGraaf

I want to create a long-running RMI server, which makes an object
available to remote hosts, and does nothing else. However, the server
consistently exists with no exception or error after >=60 seconds. My
best guess is that the program is running off the end of main(), and my
object is getting garbage collected 60 seconds later.

Is there a better way to prevent my server from exiting than waiting on
a dummy object or going into a sleep loop?

Here's (a reduced version of) my code:
RemoteInterface.java:
public interface RemoteInterface extends java.rmi.Remote
{
public String doRequest() throws java.rmi.RemoteException;
}

RMIServer.java
import java.rmi.*;
import java.rmi.server.*;

public class RMIServer extends UnicastRemoteObject implements
RemoteInterface
{
public RMIServer() throws RemoteException
{
super();
}

public String doRequest()
{
System.out.println("executing");
return "done";
}

public static void main(String[] args)
{
try {
// create a remote object and register it
RMIServer obj = new RMIServer();
Naming.rebind("rmi://localhost:1099/object", obj);
}

// throws if the URL to the rmiregistry is invalid
catch (java.net.MalformedURLException e) {
System.err.println("Malformed URL: " + e);
}
catch (RemoteException e) {
System.err.println("RMI error: " + e);
}
}
}

Rennie
 
K

Kevin McMurtrie

Just wait for a notification that won't come. When all non-daemon
threads exit, the JVM begins shutdown.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,262
Messages
2,571,044
Members
48,769
Latest member
Clifft

Latest Threads

Top