• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how does RMI handle threads?

 
Kyle Tang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I heard people saying "RMI handles threads for you". but what exactly does this mean?
Thanks!
[ September 23, 2002: Message edited by: Kyle Tang ]
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea -- it's too general a statement to mean anything to me.
 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means that RMI method calls work exactly like local method calls with respect to multithreaded code. If you want your multithreaded code to work in either case, you must make your methods thread safe.
Geoffrey
 
Kyle Tang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
I was reading sun.rmi source code these days trying to dig it out. Didn't find much. Just found that UnicastRemoteObject() will cause a thread to be created, and start to listen at a certain port.
Actually what I was thinking is, if you have 1 single Remote object, and you start multiple clients to call the methods on this Remote object, what will happen? Do I need to make the Remote object to be thread-safe, ie, make some part of the remote method syncronized, etc? Or, does RMI automatically make the multiple client calls thread-safe?
Thanks!
 
Kyle Tang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
just found that after the remote object got "exported", RMI creates a thread, and start listen(). later on when a RemoteRef.invoke() is called, ie, a client does a RMI call, the listening thread got "accept()", and spawn a new thread to process this RMI call. So each client call match a new Server side thread. RMI does nothing to make these Server side threads to be thread-safe. So if there are multiple clients making remote calls at the same time, the Remote object methods has to take care of the syncronization.
thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic