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

  • Home
  • SEARCH
  • 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 7050665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:10:15+00:00 2026-05-28T03:10:15+00:00

I have a problem (maybe a fundamental understanding problem), with Java RMI. I have

  • 0

I have a problem (maybe a fundamental understanding problem), with Java RMI. I have a “server” object and man “clients”. Both are RMI objects (they implement to different Remote interfaces). The clients register themself at the server, and are stored in a list. The server will later distribute some work to the clients and fetch the result.

The problem is, that the list, where the clients are stored, seems to be not shared (I have no better description). I.e. if one client calls the server interface and registers itself, it will be added into the list, but the call seems to be only locally.

Following is an minimal example of the code:

IRemote.java

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface IRemote extends Remote {
    public void remoteCall() throws RemoteException;
}

RemoteImple.java

import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.ArrayList;

public class RemoteImpl implements IRemote, Serializable {
    public ArrayList<Integer> list = new ArrayList<Integer>();

    @Override
    public void remoteCall() throws RemoteException {
        list.add(23);
        System.out.println("In remote call: "+list.size());
    }
}

RegAndServer.java

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class RegAndServer {
    public static void main(String[] args) throws RemoteException, InterruptedException {
        Registry reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
        RemoteImpl impl = new RemoteImpl();
        reg.rebind("server", impl);

        while(true) {
            Thread.sleep(2000);
            System.out.println("Server sees: "+impl.list.size());
        }
    }
}

Client.java

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

public class Client {
    public static void main(String[] args) throws MalformedURLException, RemoteException, NotBoundException {
        IRemote remote = (IRemote) Naming.lookup("//localhost/server");
        remote.remoteCall();
    }
}

If I start the server java RegAndServer it will output “Server sees: 0” in a loop. If I now start the client java Client in a different shell I get “In remote call: 1”. However the server process still outputs “Server sees: 0”.

Why is this? What am I doing wrong? I actually thought I had understood Java RMI 🙁

  • 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-05-28T03:10:16+00:00Added an answer on May 28, 2026 at 3:10 am

    Your RemoteImpl should not be Serializable (you don’t want to send a copy of it over the network, just the stub, and the runtime does that for you), and must extend UnicastRemoteObject

    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    import java.util.ArrayList;
    
    public class RemoteImpl extends UnicastRemoteObject implements IRemote {
        public ArrayList<Integer> list = new ArrayList<Integer>();
    
        public RemoteImpl() throws RemoteException {
    
        }
        @Override
        public void remoteCall() throws RemoteException {
            list.add(23);
            System.out.println("In remote call: "+list.size());
        }
    }
    

    Keep in mind that the code is executed in the sever side, even though the call is made from the client, so the message “In remote call” will appear in the server log.

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

Sidebar

Related Questions

Maybe world peace would be easier, but I have a problem with the widths
i have problem with has_many_polymorphs, maybe you can help me. I have some models
hello i have a problem that's maybe difficult to descripe, i have an application,
I have problem with my app. It is developed for both devices. On iPad
I read this topic, but his problem maybe different from mine Writing to both
I have a problem (or maybe a discussion). I've been surfing the Internet in
I have a simple problem (maybe) with my code... I have a facebook button
Hello I have very strange problem and maybe some of you could help my.
I have problem with this method in NLog library: NLog.Targets.Wrappers.AsyncTargetWrapper.ProcessPendingEvents(object state) It consume too
I have problem that on server include() function does not want to work and

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.