wood burning stoves 2.0*
The moose likes Distributed Java and the fly likes how does RMI handle threads? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "how does RMI handle threads?" Watch "how does RMI handle threads?" New topic

how does RMI handle threads?

Kyle Tang
Ranch Hand

Joined: Aug 22, 2002
Posts: 78
Hi all,
I heard people saying "RMI handles threads for you". but what exactly does this mean?
[ September 23, 2002: Message edited by: Kyle Tang ]

Kyle Tang<br />SCJP 91<br />SCWCD 96<br />SCBCD 95
Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292

I have no idea -- it's too general a statement to mean anything to me.
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
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.

Sun Certified Programmer for the Java 2 Platform
Kyle Tang
Ranch Hand

Joined: Aug 22, 2002
Posts: 78
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?
Kyle Tang
Ranch Hand

Joined: Aug 22, 2002
Posts: 78
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.
subject: how does RMI handle threads?
Similar Threads
Does RMI.....
RMI Sever Supports Multi Threading ??
server side
I thought my urlybird program is ready
RMI multi thread safe