Long Thai
Long Thai

Reputation: 407

RMI - create thread on server to serve client

I'm developing a application using rmi which allow client to login, perform some task and logout. I know that each client is considered as one thread when it call a method on server, however, all clients' threads call to the same object created on server. So now, I want to for each client login successfully, a new thread is created (and a new object, which is used by only one client, is binded, too), a thread terminates when client logout. Hence, each client has its own server's object to work with.

Thank you very much.

Cheers

Upvotes: 0

Views: 1534

Answers (1)

user207421
user207421

Reputation: 310907

I know that each client is considered as one thread when it call a method on server

That's not correct. The relationship between clients and server threads is undefined in RMI.

In any case you don't need a thread per client. You need a remote object per client. This is a job for the Session pattern:

public interface Login extends Remote
{
  Session login(String credentials) throws RemoteException;
}

public interface Session extends Remote
{
  // Your API here
}

Have your Login implementation object return a new Session implementation object for every client.

Upvotes: 2

Related Questions