File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes threaded server?! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "threaded server?!" Watch "threaded server?!" New topic
Author

threaded server?!

emil dragan
Greenhorn

Joined: Dec 11, 2001
Posts: 10
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

Joined: Jun 13, 2001
Posts: 84
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

Joined: Dec 11, 2001
Posts: 10
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

Joined: Jun 04, 2001
Posts: 75
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).]


SCJA, SCJD, MCSD
Trevor Dunn
Ranch Hand

Joined: Jun 13, 2001
Posts: 84
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: threaded server?!
 
Similar Threads
FBN - Multithreaded server problem
RMI server threading?
Queue in Java
Passed SCJD 368/400
Threads 003: Server-Side Strategies