2

I have a bunch of java programs that are run every few minutes. These programs are started by a script every few minutes and terminates in less than a minute. Most of them are single threaded and to access MySQL DB I use:

DriverManager.getConnection()

They just need to connect once, and execute a query. Now I'm adding a new program to this group which is multi threaded and all the threads need to access DB concurrently. I'm thinking of using a DB connection pool (c3p0) for this.

My question is, as all these programs share a common DAO for accessing DB, is there an overhead of using a DB connection pool for the single threaded programs even though they just need one connection? I'm planning to set initialPool size to 1, min pool size to 1 and max pool size to 10.

1 Answer 1

2

The main goal of connection pools is to have some ready-to-use connections, rather then open and close each time you want to get a connection. This approach saves quite enough time in terms if DB is used quite often.

Apache DBCP is single-threaded, but anyway it significantly increases performance, if your application uses DB connection very often.

c3p0 is a good choice, but for choosing proper connection pool please check this discussion: Connection pooling options with JDBC: DBCP vs C3P0

Sign up to request clarification or add additional context in comments.

2 Comments

My question is if there is any performance issue on using a DB Connection Pool with just one connection vs just obtaining a connection using DriverManager.getConnection()
There shouldn't be any performance issues at least just because you won't close Connection at all. Since you are planning to set maxPoolSize to 10, then in this case ConnectionPool is a best choice as there won't be any locks. The only thing to consider is that ConnectionPool needs external libraries, meanwhile DriverManager.getConnection() needs only JDK.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.