This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java DAO pattern: singleton and threadsafe?

 
koen ja
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

Here's my problem:
I'm working on a legacy J2EE application that uses the DAO pattern
and implements all DAO's as singletons. There's one abstract DAO
superclass.

But this class holds the connection to the database as an instance
variable.
Which, in my opinion, is not thread safe.

If multiple clients would make a call simultaneously, the very same
connection
would be used for the different calls, resulting in an exception on
the app server.

I think a different connection should be gotten from the datasource
connection
pool on everycall? And that the datasource itself should be an
instance variable.

All opinons are appreciated!

Thanks,
Koen
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by koen ja:
I think a different connection should be gotten from the datasource
connection
pool on everycall? And that the datasource itself should be an
instance variable.

I completely agree with this!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic