Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization 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: 34095
337
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