C3P0 创建太多线程和计时器
我有一个在 Tomcat 上运行的 Java Web 应用程序,带有 Hibernate 和 C3P0。所有实体类和 JPA 控制器都是使用 Netbeans 向导完成的。有一个 servlet,在调用时会在数据库中插入许多对象(使用 JPA 控制器)。
问题是,使用 Java VisualVM 查看我的 web 应用程序时,我发现有很多 Timers 和 com.mchange.v2.async.ThreadPoolAsynchronousRunner 类,并且它随着时间的推移而增长。对于每个计时器,都会创建 3 个线程。
所有线程和计时器都处于 WAIT 状态,我认为这个问题可能是由于应用程序出现 OutOfMemory 错误(Java 堆空间)所致。产生。即使我在 MySQL Administrator 中看到当 servlet 结束任务时所有连接都已关闭,但可能某些对象仍在内存中。
C3P0 创建超过 700 个 Timeras 和 2100 个处于“WAIT”状态的线程,这正常吗?
谢谢埃泽奎尔
I have a Java webapp running on Tomcat, with Hibernate and C3P0. All entity classes and JPA Controllers were done with Netbeans wizzard. There is a servlet that when called inserts many objects in the database (using the JPA controllers).
The problem is that looking at my webapp with Java VisualVM I found that there are a lot of Timers and com.mchange.v2.async.ThreadPoolAsynchronousRunner classes, and it grows as time pass. For every Timer there are 3 Threads created.
All the Threads and Timers are in WAIT state, and I think that this problem may be behind an OutOfMemory error (Java Heap Space) that the app. produces. And even though I see at MySQL Administrator that all the connections are closed when the servlet ends the task, may be some objects are still in memory.
Is it normal that C3P0 creates leaves more than 700 Timeras and 2100 Threads in "WAIT" state?
Thanks
Ezequiel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您没有发布任何代码,我只能猜测,但这听起来很像您正在创建很多池。
您应该确保您实际上重用了一个池,而不是每次需要连接时都创建一个池。
同样的事情也发生在我身上一次(偶然)。虽然我没有遇到内存不足的问题,但达到了数据库服务器上的最大连接限制。
As you did not post any code, I can only guess, but it sounds pretty much like you're creating lots of pools.
You should make sure, that you actually reuse one pool instead of creating one each time you need a connection.
Same thing happened to me once (accidentally). Though I did not ran into OutOfMemory, but reached the max-connection-limit on the database-server.