File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multithreading in RMI server??

 
Narayana Swamy
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Vladan Radovanovic
Ranch Hand
Posts: 216
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic