batman
batman

Reputation: 3685

Handling dynamic database connections in Java

I'm trying to build some dashboard application which allows the user to connect to their database and run queries. The resultset then will be feed into the charts for rendering. I want to understand few things:

  1. As you could guess, each user might have different database sources configured, which I will store in my database. Lets say when 100 users are logging to my application and trying to build up a dashboard. Now I would end up opening 100 connection at the same time (for each user as per their database connection details), which I guess is really bad.

  2. At the same time, I cannot create database connection pool (when my application starts up for each user's database source), as I won't be sure whether which user will pick up their database configuration to build a dashboard. Again I might end up in creating pool which may not be used at all!

How we can handle the same?

Upvotes: 0

Views: 134

Answers (1)

light_303
light_303

Reputation: 2111

It sounds like you do want to at least cache connections per datasource and "close" them when they become idle/unused for long enough.

Opening 100 connections itself does not sound like a huge problem unless you do not run out of memory or file descriptors.

Upvotes: 1

Related Questions