~/ learn/ comp-348/ cards/ Worked build: the prime service, and its failure modes
1 of 6

Type the server bootstrap: strong reference, export, registry, rebind

Type the server bootstrap: strong reference, export, registry, rebind

Answer

private static PrimeServiceImpl impl; // strong reference outlives main public static void main(String[] args) throws Exception { impl = new PrimeServiceImpl(); PrimeService stub = (PrimeService) UnicastRemoteObject.exportObject(impl, 0); Registry registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT); registry.rebind(PrimeService.NAME, stub); System.out.println("bound as " + PrimeService.NAME); }

The static field is what stops distributed GC from collecting the implementation once the last client lease lapses. main can then return — RMI keeps non-daemon listener threads alive while the object stays exported.

JDK javadoc java.rmi.registry.LocateRegistry; java.rmi.server.UnicastRemoteObject

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/25a19adc-4fa1-4c8c-b479-71a41585b87d/flashcard utf-8 LF