问题
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
回答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.
来源:https://stackoverflow.com/questions/6651263/c3p0-creating-too-many-threads-and-timers