Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anyone have any good tips on debugging connection leaks on GlassFish?

I am currently debugging a GlassFish server which contains an application that has memory leaks sporadically, eventually leading to having to restart the server to free the pool (pool purging is only available in Glassfish 3 I was told).

When I debug these kinds of errors today I look through the server log around the time when I can see that our monitoring has reported that the pool has grown and see if there is any interesting errors or similar around this point.

Does anyone have any better ways of debugging problems like these?

All the applications are EJB/EAR's which use annotation to inject datasources. The applications then use the datasource to get a connection. Ofcourse every connection is supposed to be closed by the programmers, but I guess someone has forgot it in a case here.

share|improve this question
up vote 1 down vote accepted

I think a good way for tracing memory leaks is to attach VisualVM to the running Java process (in this case a GF instance) and look into the reference tree of heap dumps.

Another way that comes to my mind, but requires some work, would be to write your own connection/connection pool wrapper and log a stack trace every time connection is taken from the pool as well as closed.

share|improve this answer

You can setup "Connection leak reclaim" options for connection pools and you can get full stack traces indicating the root causes in a server log.

See the documentation page -

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.