Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8642167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:42:31+00:00 2026-06-12T11:42:31+00:00

While getting my hands dirty with RMI, I got a java.rmi.NoSuchObjectException exception, which led

  • 0

While getting my hands dirty with RMI, I got a java.rmi.NoSuchObjectException exception, which led me to this question: java.rmi.NoSuchObjectException: no such object in table but my question is different.

I’m creating the impl object in my main method and hence in the main thread. If I do this:

FooImpl fi = new FooImpl();
foo = (Foo) UnicastRemoteObject.exportObject(fi, 0);

things work fine.

If I do this:

foo = (Foo) UnicastRemoteObject.exportObject(new FooImpl(), 0);

I see that FooImpl instance is collected and then I get the aforementioned exception.

foo is a static reference that I’m initializng in main; and another remote object returns foo from one of its methods. So a client gets that remote object first, then gets foo from it, and then calls a method on foo and that’s when I get the exception as explained above. So why is it happening this way?

EDIT: here’s my main method

public static void main(String[] args) throws RemoteException, AlreadyBoundException 
{

    Server server = new Server();
    Hello stub = (Hello) UnicastRemoteObject.exportObject(server, 0);

    FooImpl fi = new FooImpl();
    foo = (Foo) UnicastRemoteObject.exportObject(fi, 0);

    Registry registry = LocateRegistry.getRegistry();
    registry.bind("Hello", stub);       
    System.out.println("Server ready!");        
}

In client, I’m getting hello and calling a method on it which gives me foo and then calling a method on foo.

EDIT2: If I use

Hello stub = (Hello) UnicastRemoteObject.exportObject(new Server(), 0);

and bind foo first and then hello, then same exception is thrown when I try to access hello because now it’s Server instance which is getting collected. Really weird stuff!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:42:33+00:00Added an answer on June 12, 2026 at 11:42 am

    Both approaches are liable to fail. There’s no real difference between them in terms of variable scoping.

    The problem more usually seen in these situations is the Registry itself, when created by LocateRegistry.createRegistry(), which you aren’t doing. If you were, the created Registry itself can be GC’d too: you must keep the Registry reference in a static variable. Then it won’t be GC’d, and it will prevent the stub foo from being GC’d, and the stub will keep the FooImpl from being DGC’d and therefore GC’d.

    In your case you would be better off keeping the remote object references (servers, not stubs) in static variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the output I'm getting while compiling my class under Lubuntu 12.04 32bit
undefined method 'key?' for nil:NilClass This is the error I am getting while going
m getting exception while taping on listView item.. @Override protected void onCreate(Bundle savedInstanceState) {
I was just getting ready to get my hands rough with Nodejs, but while
I keep getting this writing to a closed file error while trying to compile
While getting into a nice long argument over memory locations vs pointers vs associated
While getting our WCF Data Service ready for production we encountered an issue with
i am getting following error while getting data from dictionary -[__NSCFString objectForKey:]: unrecognized selector
I have an issue while getting the file name with out extension from a
I've spent a good while getting my AVR development system set up with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.