File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Multithreading in RMI server?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Multithreading in RMI server??" Watch "Multithreading in RMI server??" New topic
Author

Multithreading in RMI server??

Narayana Swamy
Greenhorn

Joined: Jul 03, 2000
Posts: 6
I have started tinkering with RMI in java. It is very different from the network socket concept and seems to be much more powerful. But how do you invoke multithreading in the main method of a RMI server to server multiple clients? or does RMI automatically take care of this. Ok, what I mean by my question is: In normal client-server code using sockets, I would normally use a code like this in the main method of the server:
try {
while(true) {
// Blocks until a connection occurs;
Socket socket = s.accept();
try {
System.out.println("opening new Server thread");
new ServerThread(socket);
} catch(IOException e) {
// If it fails, close the socket,
// otherwise the thread will close it
socket.close();
}
The ServerThread would do the work required of the server.
But in RMI, there is no such a thing as s.accept(). All one does is have a statement like Naming.rebind("test",t); and it waits for client connections on a separate thread. My question is does RMI automatically create new threads as every client connects to the server?


swamy
Vladan Radovanovic
Ranch Hand

Joined: Mar 20, 2000
Posts: 216
A bit late reply but RMI does not span a new thread for every single new client. I think that it does not span a new thread unless really needs to.
Here is a paragraph that explains it.
A method dispatched by the RMI runtime to a remote object implementation may or may not execute in a separate thread. The RMI runtime makes no guarantees with respect to mapping remote object invocations to threads. Since remote method invocation on the same remote object may execute concurrently, a remote object implementation needs to make sure its implementation is thread-safe.

Originally posted by Narayana Swamy:
I have started tinkering with RMI in java. It is very different from the network socket concept and seems to be much more powerful. But how do you invoke multithreading in the main method of a RMI server to server multiple clients? or does RMI automatically take care of this. Ok, what I mean by my question is: In normal client-server code using sockets, I would normally use a code like this in the main method of the server:
try {
while(true) {
// Blocks until a connection occurs;
Socket socket = s.accept();
try {
System.out.println("opening new Server thread");
new ServerThread(socket);
} catch(IOException e) {
// If it fails, close the socket,
// otherwise the thread will close it
socket.close();
}
The ServerThread would do the work required of the server.
But in RMI, there is no such a thing as s.accept(). All one does is have a statement like Naming.rebind("test",t); and it waits for client connections on a separate thread. My question is does RMI automatically create new threads as every client connects to the server?

 
 
subject: Multithreading in RMI server??
 
Similar Threads
HELP: Muilt-Threaded Server
multiple request handling in Sockets
the max number of clients to multithread the socket server
Client-Server Problem
Multithread-call center support