• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Multithreading in RMI server??

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?


 
Is that a spider in your hair? Here, threaten it with this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic