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:
我有一堆每隔几分钟运行一次的java程序。这些程序每隔几分钟由一个脚本启动,并在不到一分钟的时间内终止。他们中的大多数都是单线程的,并且我使用的是访问MySQL DB:
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.
他们只需要连接一次,然后执行查询。现在,我正在向该组添加一个新程序,该程序是多线程的,并且所有线程都需要同时访问DB。我正在考虑使用数据库连接池(c3p0)。
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.
我的问题是,由于所有这些程序共享一个用于访问数据库的公共DAO,即使它们只需要一个连接,是否会为单线程程序使用数据库连接池的开销?我打算将initialPool大小设置为1,将最小池大小设置为1,将最大池大小设置为10。
1 个解决方案
#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.
连接池的主要目标是拥有一些现成的连接,而不是每次想要建立连接时打开和关闭。如果经常使用DB,这种方法可以节省足够的时间。
Apache DBCP is single-threaded, but anyway it significantly increases performance, if your application uses DB connection very often.
Apache DBCP是单线程的,但无论如何,如果您的应用程序经常使用数据库连接,它会显着提高性能。
c3p0 is a good choice, but for choosing proper connection pool please check this discussion: Connection pooling options with JDBC: DBCP vs C3P0
c3p0是一个不错的选择,但是为了选择合适的连接池,请检查以下讨论:JDBC连接池选项:DBCP vs C3P0
#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.
连接池的主要目标是拥有一些现成的连接,而不是每次想要建立连接时打开和关闭。如果经常使用DB,这种方法可以节省足够的时间。
Apache DBCP is single-threaded, but anyway it significantly increases performance, if your application uses DB connection very often.
Apache DBCP是单线程的,但无论如何,如果您的应用程序经常使用数据库连接,它会显着提高性能。
c3p0 is a good choice, but for choosing proper connection pool please check this discussion: Connection pooling options with JDBC: DBCP vs C3P0
c3p0是一个不错的选择,但是为了选择合适的连接池,请检查以下讨论:JDBC连接池选项:DBCP vs C3P0