Hello, I am currently trying to make my DataServer multi threaded. I have used RMI to implement the server. It works as follows: Clients look up the DataServer and get a Connection. Connection is a remote object that implements the public methods of the Data class. When a call is made on the Connection object (i.e getRecordCount()), it creates a new Request object, puts the Request on an queue and blocks. The Request is taken off the queue by a ThreadPoolManager, that executes it in a separate thread. Once the Request is complete, the result is returned to the client's method and the client is unblocked so it can receive the result of the request. Most of this is working well, but seems like overkil. Any comments / ideas on how to make an RMI server multi threaded?
Gavin, I simply created a Server that created multiple Servants that each obtained a reference to one central Data object. This lets RMI manage the handing out of connections and frees you from having to implement this mechanism yourself. The central Data object has the synchronized methods, so each Servant will block as needed when executing. Good luck!
Gavin, RMI handles multithreading... May I ask what your motivation was for implementing a multithreaded add-on of your own? Cheers, Dave
posted 19 years ago
Hello, My motivation was more a "learning experience" than anything else. I have been working with Java commercially for about two year, but this is my first experiment with RMI so I really wanted to test the technology. My "project" motivation was to produce a server that could: 1) Have a pool of worker threads that handle the tasks. This will reduce the creation of Threads (which is a very expensive task and does not scale.) 2) Provide a mechanism that can work in sync and async mode. 3) Improve the basic RMI multi-threading (which I understand is very implementation-dependent) 4) Use a JDBC like mechanism so the change to a JDBC db would be as smooth as possible. Cheers,
I think using a pool does not give you that much. Yes: it reduces the overhead required to create a new thread. But: RMI has already created a separate thread for you (or probably reused an existing one). So the code is executed in parallel anyway, so I would gues that putting a Threadpool on top of it won't provide that much benefits, except that your scheduling can be much more sophisticated (Orcale MTS architecture, eeh?). But that should far beyond the scope of this assignment. At least I hope so ;-)
Rainer<br />SCJP, SCJD, SCWCD
Seriously Rick? Seriously? You might as well just read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop