• 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

Java DAO pattern: singleton and threadsafe?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic