The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Help on Threadsafe requirement Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Developer Certification (SCJD/OCMJD)
Reply Bookmark "Help on Threadsafe requirement" Watch "Help on Threadsafe requirement" New topic
Author

Help on Threadsafe requirement

Rudy Yeung
Ranch Hand

Joined: Dec 27, 2000
Posts: 183
In the assignment specification under the section "Writing the Data Server", it wrote "You must create a data server that will accept multiple concurrent network connections and allow them to interrogate and manioulate the database. Because multiple concurrent connections may exist, you must make both your server and the suncertify.db.classes threadsafe. You may implement your threaded server in more than one class if you choose."
Rudy Yeung
Ranch Hand

Joined: Dec 27, 2000
Posts: 183
Sorry, I have pressed the enter key by mistake.
In the assignment specification under the section "Writing the Data Server", it wrote "You must create a data server that will accept multiple concurrent network connections and allow them to interrogate and manioulate the database. Because multiple concurrent connections may exist, you must make both your server and the suncertify.db.classes threadsafe. You may implement your threaded server in more than one class if you choose."
Unlike socketing, the RMI approach which I use does not require to create a thread at the server for every new client connection. The RMI itself has already handled the thread internally. If that is the case, how am I gonna to fulfil the threadsafe requirement for the server and suncertify.db.classes? Or have I actually fulfilled it?
vladimir levin
Ranch Hand

Joined: Dec 19, 2000
Posts: 45
I've read that basically when you call a method remotely, you
have no idea which thread may be handling the request. Multiple
clients calling the same remote method will quite possibly end
up spawing a separate thread for each call. What this means is
that your remote methods have to be thread safe. If the methods
are synchronized against the Data object... well... that seems
to fulfill the requirement nicely. So for the most part, you
don't have to worry about much when you're using RMI, but you
do have to keep in mind that all your remote methods must be
made thread safe -- that is any number of threads could
potentially be calling them concurrently.
I hope that makes sense.
Vlad

Rudy Yeung
Ranch Hand

Joined: Dec 27, 2000
Posts: 183
Vlad,
I agree with what you have said. If we closely take a look at the given data class. All the database access related methods i.e. read, write, add, modify, delete and delete etc. have synchronized keyword in the method declaration. This means the given data class is meant for threadsafe. I do not see anywhere to make the database access and data class more threadsafe except the lock() and unlock() methods implementation. Please correct me if I am wrong.
Rudy
Matt DeLacey
Ranch Hand

Joined: Oct 12, 2000
Posts: 318
Not sure what you are asking. The lock and unlock methods are the means by which you make concurrent access to the db "safe" (aside from what's already builtin). Or at least that's my take.
With Respect,
Matt
Rishi Kumar
Greenhorn

Joined: Mar 28, 2001
Posts: 19
Can't we just use synchronized to the locking and unlocking?
Why we have to have these methods?
Thanks
------------------
Rishi Kumar,SCJP


Rishi Kumar,SCJP SCJD SCWCD
 
 
subject: Help on Threadsafe requirement
 
Threads others viewed
Server and suncertify.db classes threadsafe
Data singleton
HELP: Muilt-Threaded Server
Locks without Client IDs?
Does server need threads?
developer file tools