开发者

RMI - create thread on server to serve client

开发者 https://www.devze.com 2023-02-02 22:34 出处:网络
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 cli

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' th开发者_Python百科reads 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消