When using Java’s Remote Method Invocation (RMI), you may have defined a server class that extends java.rmi.server.UnicastRemoteObject. Extending UnicastRemoteObject makes your class capable of handling incoming calls, and is acceptable in many cases. However, you sometimes will want to extend a different class and still retain the ability to handle incoming RMI calls. Fortunately, there’s a simple solution to this problem. The UnicastRemoteObject constructor makes the object accessible by calling the static exportObject() method, and because this method is public, your class can call it directly. In this code, an instance of RMIServer is created, exported, and added to the registry. Although it does not extend UnicastRemoteObject, it can be accessed through registry lookup and called using RMI.
import java.rmi.*;import java.rmi.server.*;public class RMIServer extends Object implements RMIInterface { public static void main(String[] args) throws Exception { RMIServer s = new RMIServer(); UnicastRemoteObject.exportObject(s); Naming.rebind("MyServer", s); } // public static void main()} // public class RMIServer extends Object
Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.
Related Posts
- Automate Business Processes with Azure Logic Apps
- Capture Errors from a BackGroundWorker Component in the RunWorkerCompleted Event
- Discover Extended Compatibility Options in the Updated ODBC Driver for xBase
- Search for Text Inside All the SQL Procedures in Your Database
- Silent Hill 2 remake hands-on preview






















