WildFly 9 is based on the latest release of IronJacamar which contains several enhancements. One of these, is the capability to detect Connection leaks in your applications. Let's see how to get to grips with it.

In order to detect Connection leaks you have to add a couple of properties to your startup script. Under windows:

set "JAVA_OPTS=%JAVA_OPTS% -Dironjacamar.mcp=org.jboss.jca.core.connectionmanager.pool.mcp.LeakDumperManagedConnectionPool -Dironjacamar.leaklog=leaks.txt"

 When using Linux:

JAVA_OPTS="$JAVA_OPTS -Dironjacamar.mcp=org.jboss.jca.core.connectionmanager.pool.mcp.LeakDumperManagedConnectionPool -Dironjacamar.leaklog=leaks.txt"

 The above properties will acttivate the LeakDumperManagerConnectionPool which will trace the leaks in the file named leaks.txt.

In order to trigger the LeakDumper, you need to flush the Connections in the pool, once that you have a suspect of a Connection Leak:


Now check the file leaks.txt which has been produced:

Leak detected in pool: PostgreSQL
  ConnectionListener: 1c6c192
  Allocation timestamp: 1438520410260
  Allocation stacktrack:
java.lang.Throwable: ALLOCATION LEAK
        at org.jboss.jca.core.connectionmanager.pool.mcp.LeakDumperManagedConnectionPool.getConnection(LeakDumperManagedConnectionPool.java:96)
. . . . . org.jboss.as.connector.subsystems.datasources.WildFlyDataSource.getConnection(WildFlyDataSource.java:67)
		at com.sample.LeakServlet.processRequest(LeakServlet.java:40)
		at com.sample.LeakServlet.doGet(LeakServlet.java:72)

As you can see we have got an interesting information: the leak was produced by the com.sampleLeakServlet in the method processRequest (line 40) and it was reported at the timestamp indicated above.

By the way, you can convert the timestamp in an human readable date with few rows of Java code:

Timestamp stamp = new Timestamp(1438520410260);
Date date = new Date(stamp.getTime());

 That's all!



Related articles available on mastertheboss.com

Wildfly 8 introduction

JBoss AS has a new name: as you probably know future versions of

Configuring Eclipse to use WildFly

How do I integrate WildFly with Eclipse? This tutorial shows how

Maven configuration for Java EE 7 projects on WildFly

In this tutorial we will learn how to configure Maven Project Obj

Running WildFly with JDK 8

The JDK 1.8 early access is available for download at Oracle's si

Patching WildFly application server

The final version of WildFly 8.1.0 has been released and it conta

Configuring WildFly Batch Job Repository

WildFly ships with a subsystem named batch which is the administr