• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it Okay if a DAO class is made as Singleton

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assume that we have methods such as insert , update , select and delete inside my DAO class . So please tell me if i make this DAO class as Singleton .

In my opinion this saves a lot of memory .please guide .

But as per my knowledge as DAO methods contains reference to connection object , so there would be a race around condition .

Please share your views on this .
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's a singleton, you have to worry about concurrency. Once concurrency is taken care of, you can load-test your application with singleton dao's and prototype dao's, and compare the results to know which is the right option for you. I highly doubt that a singleton will be the better approach. It will be difficult to take care of all aspects of concurrency where it would be no challenge with prototypes, and a singleton blocking at long-running queries will cause your users severe hair loss.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , Thanks for th reply

In what case we need to worry about the Concurency in which case

1.If the same user is doing multiple operarations with rspect to Database ??

2. Or from a Different User request the concurrency issues might arise ??

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Processing more than one request at a time would obviously cause trouble if you could only have one instance of a DAO class. All other requests would just have to wait - completely contrary to the idea of DAO objects.

The whole idea of DAO objects is to provide an instance which is independent of all others to conveniently hold a particular set of data.

See this rather complete wikipedia article.

Bill
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Processing more than one request at a time would obviously cause trouble if you could only have one instance of a DAO class.


I think i am close to my question now .
This would impact if there are multiple requests from a Single User ??

Or

Even a request from a different user ??

Please reply .
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran Va wrote:
I think i am close to my question now .
This would impact if there are multiple requests from a Single User ??

Or

Even a request from a different user ??
Please reply .


It's the same whether request is from the same user or from a different user as long as your DAO is a singleton.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic