• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

One instance of Data for all client or one for each

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Is it best to have the Data class a singleton, used through a remote reference by all clients, or is it best to have one instance for every clients ?
If only one instance is chosen, then only one RandomFileAcces is used by all clients, which makes the th reading non-concurrent.
If one instance is assigned to each client, the addition by a client of a new record to the database can be overwritten by another client (unaware of the previous addition).
In both cases, the Data class will have to be slightly modified: collection RandomAccessFile in the first case and shared database state variables in the second.
Am I completely wrong or does it make sense ?
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would only use one instance of Data for all clients, but I would avoid enforcing this relationship with the singleton pattern. Search this forum for somne great discussions on this.
As far as "concurrency", all the methods in Data that interact with db.db are synchronized so the point is moot. Don't worry about it. Also, you will not need to modify Data in either case.
-BJ
Here is a link to an article about applying the factory pattern to getting references to remote objects:
RMI Factory Pattern
[ March 17, 2003: Message edited by: BJ Grau ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic