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

NX: Concurrent Data

 
Javini Javono
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My design exposes Data to the client (or more specifically, the
DBMain interface). This question ignores RMI.
My DBMain interface has only one argument: the record number:
like this:
public String[] read(int recordNumber) throws RecordNotFoundException;
However, as has been pointed out, the client needs to have a unique ID
so that the clientA does not unlock, for instance, a record locked by
clientB.
This is no problem, since one unique Data is given to each unique client,
and Data will have an instance variable representing this clientId.
However, I have been considering that I might want to allow one client
to access the database with multiple threads concurrently. Here are possible
solutions:
1. The client will be forced to use one Data for each communication with
the database. The client can request more than one Data to carry out
concurrent communication, but, each Data the client has can not be
multi-threaded. For example, the client would use one instance of Data
to read record 10 while simultaneously using another instance of Data
to read record 11 (and each instance of Data would, of course, have
it's own unique clientId).
2. To use multi-threading against one Data instance, the client would,
by convention, have to call new methods which accept the clientId as
an argument:
public String[] read(int recordNumber, String uniqueId) throws RecordNotFoundException
This seems fine, but I'm not sure I'd like to count on the client following
the conventions; but, perhaps this will be alright, since we are already
assuming that the client won't lock all the database records and maliciously
call Thread.sleep(forEternity).
I was unable to think of any other alternatives at this time (as we cannot rely on
thread ID's).
If you have any other ideas, please let me know?
Thanks,
Javini Javono
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Javini,
You are over engineering your solution. Sun have not asked for an individual client to use multiple threads to book multiple records simultaneously - so you don't have to try and provide it.
Since you have a unique instance of the Data class for each connected client, then you could explicitly block the client from calling a method multiple times concurrently if you really wanted to.
But all I would suggest you do is put a comment in your design decisions document stating that you are not catering for this issue.
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic