0

I am creating an application that will use a connection pool for database connections and I want to ensure that only one connection pool is created for the whole application to use. I was going to create a singleton to ensure there could be one connection pool ever opened, but many people suggest avoiding singletons. What are my alternatives, and what would that look like to the clients calling my connection manager?

yellavon
  • 2,821
  • 12
  • 52
  • 66

1 Answers1

1

If you are running standalone application , I dont see an problem with Singleton. It is purely depends upon how you are ensuring it is single instance.

IMHO Enum is the best of creating SingleTon . And Off course , I assume you are handling proper synchronization on your methods to avoid same connection shared multiple clients and unwanted usecase

You dont need to reinvent the wheel , you can use Apache DBCP Connection Pool and the sample

One answer from SO

If you are running in Application servers , then singleton is overkill . In App servers Singleton is not guarantee due to clustering. It is guarantee only per JVM . It is advise to use the datasources for the connection pool.

Community
  • 1
  • 1
Mani
  • 3,274
  • 2
  • 17
  • 27