• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Doubt about singleton pattern

 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • 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
 
Mike Southgate
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic