This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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?

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multithreading in RMI server??
 
Similar Threads
Multithread-call center support
Client-Server Problem
multiple request handling in Sockets
the max number of clients to multithread the socket server
HELP: Muilt-Threaded Server