0

I am getting this error on prod in approximately every 7-8 days. So to debug this issue I downloaded the thread dump file. This file has following thread state 100 times:

"http-8080-198" daemon prio=10 tid=0x08a62c00 nid=0x3a78 in Object.wait() [0x66467000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x87097728> (a org.apache.commons.pool.impl.GenericObjectPool$Latch)
    at java.lang.Object.wait(Object.java:485)
    at         org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1104)
    - locked <0x87097728> (a org.apache.commons.pool.impl.GenericObjectPool$Latch)

So my questions are:

  1. Is this exception because of mysql connection pool? If yes, what should I do to solve it? My MAX-Active value is 50 and MinIdle value is 1.

  2. If this is not the case then how can I know which functionality are holding threads?

Erwin Bolwidt
  • 30,799
  • 15
  • 56
  • 79
vikas27
  • 563
  • 5
  • 14
  • 36
  • can you remember what solved it for you? I am having the same problem now. Would be awesome if you can post an answer yourself of give a hint of what helped. Thanks! – patrics Oct 13 '18 at 18:30

1 Answers1

0

I am getting this error on prod in approximately every 7-8 days.

Most likely you are not cleaning up all your resource deterministically (i.e. when you have finished with them) so the connection can be returned to the pool. The GC will clean up connections periodically, but there will be times when this is not enough. In short, make sure you are always recycling your connections (unless they are dead)

Is this exception because of mysql connection pool?

This is not an exception it is the stack trace you asked to be dumped. In fact there is no way to see Exceptions in a thread dump (except in the very rare event you happen to see it creating an Exception)

If this is not the case then how can I know which functionality are holding threads?

These threads are in this state because they don't have anything to do. Most likely because another thread which should be doing something is taking too long. I suggest you look at the threads which are RUNNING, or WAITING in your code, to see what could be blocking your application.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Peter I am talking about my heading error "Maximum number of threads (200) created for connector with address null and port 8080". – vikas27 Sep 30 '14 at 15:30
  • @vikasTheJavaDeveloper do you have a stack trace which indicates which part of the code which reported this exception. There is no much message in Java. – Peter Lawrey Sep 30 '14 at 15:36
  • the code which connect with mysql database is showing this "java.lang.Thread.State: WAITING (on object monitor) ............" How can I return/release connection object. I am closing it right now. Any idea where I might be wrong? – vikas27 Sep 30 '14 at 18:22
  • @vikasTheJavaDeveloper when you `close()` a pooled connection it actually returns the underlying connection to the pool. Make sure you close all the resources. – Peter Lawrey Sep 30 '14 at 18:38
  • I am closing connection and statement but not resultset, can this be the issue leading to "Maximum number of threads (200)..." exception. – vikas27 Oct 01 '14 at 07:35
  • It could be. The Result Set will be closed by the GC but it might not run when you need it to. Thus the random behaviour of when it runs out of connections. – Peter Lawrey Oct 01 '14 at 07:55