• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NX: Doubt about singleton pattern

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I read in one of the postings about the use of singleton pattern to make the appliaction thread safety. But in that case, how the Sun provided interface is used? Cuase this class wont be able to implement it as the methods would be static.
I guess there must be a way to do this using wrapper or something. But I am not clear.
Can abybody give me rough class diagram of how the classes would look like in that case?
Also another question on File I/O:
I was thinking of only making update/write method thread safe and not the read method. (and I am doing this update, etc directly on file)
In that case, when some record is being updated, and at the same time a read is requested (by other client), will it not interfear? cause the file pointer will be shifted by the read.
How are you guys handaling this?
Awating for the response..
thanks,
manoj
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My interface and assignment didn't stop me from creating a private constructor and adding a static method to invoke it. So singleton worked fine for me.
Yes, the reading can interfere with the writing, synchronize all methods that do file io unless you're using FileChannels - I don't know anything about them so I can't comment.
ms
 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your input Mike.
Mike can you give me some pciture about your class inter-relationship? just to get a rough idea to understand how to put these together. I know this in bits and pieces, but not able to put them together. For ex I am not sure
how the singlton instance need to be used in data class.

Manoj
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To use the immortal words of Peter Den Haan. "Singleton is overused".
In the case of the Data class just instantiate one instance. Then you do not need to make it a Singleton. Since on the remote version the Data class can be instantiated in the ConnectionFactory class once, then the reference is what is passed to each client Connection object.
Mark
 
I guess everyone has an angle. Fine, what do you want? Just know that you cannot have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic