Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help on Threadsafe requirement

 
Rudy Yeung
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 318
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't we just use synchronized to the locking and unlocking?
Why we have to have these methods?
Thanks
------------------
Rishi Kumar,SCJP
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic