4

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

Ezequiel
  • 1,186
  • 2
  • 11
  • 11

1 Answers1

-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.

Boris
  • 4,327
  • 2
  • 19
  • 27
  • Thanks boris, I found that the same code without C3P0 consumes (by far) less memory than the same code with C3P0. How can I explicit tell C3P0 to reuse a connection pool? Or at least find out that it's creating a new pool. Thanks. – Ezequiel Jul 16 '11 at 19:36
  • You can't tell C3P0 to reuse it, you have to reuse it yourself. How you do is up to you (static variable, jndi, injection, ...) – Boris Jul 17 '11 at 09:35
  • I have same problem but answer not helping – ayengin Sep 28 '11 at 10:30