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.
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.
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 - http://docs.oracle.com/cd/E19879-01/820-4335/geveg/index.html.