hibernate连接池问题
我一生都无法摆脱 Hibernate 警告:
849 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
849 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
我看过很多其他此类帖子,但没有任何帮助。我将展示我的配置,也许有人可以看到我看不到的东西。
我正在尝试使用C3P0作为连接池框架。我的类路径中有 c3p0-0.9.1.jar 文件(以及其他 hibernate jar)。
以下是我的 persistence.xml 文件的片段:
<property name="connection.provider_class"
value="org.hibernate.connection.C3P0ConnectionProvider" />
<property name="hibernate.c3p0.acquire_increment" value="1" />
<property name="hibernate.c3p0.max_size" value="20" />
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.timeout" value="5000" />
<property name="hibernate.c3p0.max_statements" value="0" />
<property name="hibernate.c3p0.acquire_increment" value="5" />
<property name="hibernate.c3p0.idle_test_period" value="300" />
<property name="hibernate.c3p0.validate" value="false" />
我正在我的实体 Pojo 上使用 JPA 注释。所有这些都运行良好,这意味着当我运行我的应用程序时,它运行良好,CRUD 操作似乎运行良好等等(它是一个纯 Java 应用程序。它不在 Tomcat 或 JBoss 等 AppServer 中运行)。
但令我非常困扰的是,我继续看到“使用 Hibernate 内置连接池”警告,并且没有任何迹象表明 C3P0 正在运行。例如,我的 log4j 输出在启动时显示大量 org.hibernate 输出,但根本没有 C3P0 输出。我认为另一个迹象表明它没有被使用。
在我的应用程序中,我做的第一件事就是创建一个静态 EntityManagerFactory(由内部线程池共享;每个工作线程使用它来创建 EntityManager 以对并发命令执行 CRUD 操作等...) 。在生产环境中,该应用程序将经历并发数据库处理活动的大量爆发,因此正确设置数据库连接池至关重要。
据我了解,创建 EntityManagerFactory 就是“启动”连接池机制所需的全部工作。也许这是不正确的?如果是这样,我应该在应用程序中做什么来启动 C3P0?
欢迎建议/批评。
提前致谢。
For the life of me I cannot get rid of the Hibernate warning:
849 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
849 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
I have looked at lots of other such postings but nothing helps. I will show my configuration and maybe someone can see what I cannot.
I am attempting to use C3P0 as the connection pool framework. I have the c3p0-0.9.1.jar file in the classpath (with other hibernate jars).
Here is a snippet of my persistence.xml file:
<property name="connection.provider_class"
value="org.hibernate.connection.C3P0ConnectionProvider" />
<property name="hibernate.c3p0.acquire_increment" value="1" />
<property name="hibernate.c3p0.max_size" value="20" />
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.timeout" value="5000" />
<property name="hibernate.c3p0.max_statements" value="0" />
<property name="hibernate.c3p0.acquire_increment" value="5" />
<property name="hibernate.c3p0.idle_test_period" value="300" />
<property name="hibernate.c3p0.validate" value="false" />
I am using JPA annotations on my Entity Pojos. All of that is working great, meaning when i run my application, it runs fine, CRUD operations seem to work fine, etc (It is a pure-Java app. it is not running in an AppServer such as Tomcat or JBoss).
But I am very much bothered that I continue to see the "Using Hibernate built in Connection Pool" warning and no indication that C3P0 is running. For example, my log4j output shows tons of org.hibernate output at startup, but NO C3P0 output at all. Another indication it's not being used I would think.
In my application, one of the first things I do is create a static EntityManagerFactory (which is shared by an internal thread-pool; each worker-thread uses it to create an EntityManager to perform CRUD operations on concurrent commands, etc...). In a production environment, this application will experience heavy bursts of concurrent DB processing activity, so it is critical that I get the DB connection pool stuff right.
It is my understanding that the creation of the EntityManagerFactory is all that is needed to "start-up" the connection pool mechanism. Maybe this is incorrect? If so, what should I do within the application to initiate C3P0?
Advice/critique welcome.
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论