Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

threaded server?!

 
emil dragan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the server need to be multithreaded in the FBN application? I stumbled upon a statement that reads: "You may implement your threaded server in more than one class if you choose." The "threaded server" bit intrigues me. Does the server need to span multiple threads? If yes, what do I need to do special on the server side to know when a client has established a connection? Is it possible to derive some sort of client ID to be used in locking if the server is single threaded?
Thanks!
 
Trevor Dunn
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use RMI for the server then the threading is taken care of for you (Yea RMI). However if you use a sockets based server then you will need to handle the threading.
Trevor
 
emil dragan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Trevor! I just realized that the RMI takes care of the multithreading in the background. My server is too simple and I was wondering whether I'm missing something.
 
Roman Rytov
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys! I'd coax your to re-read the RMI spec.:
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. (http://java.sun.com/j2se/1.3/docs/guide/rmi/spec/rmi-arch3.html)
Although ususally your suggestion works you souldn'g rely on it (unless you're not afraid to lose several points).
I'm gonna implement a ConnectionFactory and to shoulder on it responsibility for getting new connection to the DB (RMI object that in its turn implements Runnable and here works in own thread)
[This message has been edited by Roman Rytov (edited January 02, 2002).]
 
Trevor Dunn
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roman
Of course you are right. That is what the spec says. ANd it is true you have to make your objects thread safe. But when I say RMI handles your threading I mean you do not need to write your own thread pools, or assign theads to clients etc. All these things you have to do in a socket based solution. In RMI you just have to make your objects thread safe
Trevor
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic