File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "how does RMI handle threads?" Watch "how does RMI handle threads?" New topic
Author

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?
Thanks!
[ September 23, 2002: Message edited by: Kyle Tang ]

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

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
    
    1
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


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

Joined: Aug 22, 2002
Posts: 78
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

Joined: Aug 22, 2002
Posts: 78
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how does RMI handle threads?