• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

NX: Concurrent Data

 
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic