How to Debug Clustered AppServer Instances
There used to be a big problem in trying to attach a debugger to a clustered server instance in Glassfish. As of today (build 45), it is a snap to do it!
The problem was that a cluster config could only specify one debugging port. This would work if you started one and only one server instance. As soon as you tried to start a second instance it would try to use the same jdwp port and it would fail to launch. It was (almost) impossible to debug 2 instances on the same machine at the same time.
The solution is to defer the actual port number selection. I.e. the instance needs to choose its own port. Each instance specifies a different port and, voila, problem solved.
Here is how to do it:
1. Enable debugging support for the cluster
We are using a cluster named c1. First make sure that debugging is enabled for the cluster:
asadmin set c1-config.java-config.debug-enabled=true
2. Set a variable debugging port
The syntax is ugly. Don't bother memorizing just do a get to see it, edit it and then do a set on the result like so:
asadmin get c1-config.java-config.debug-options
c1-config.java-config.debug-options = -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9009
asadmin set c1-config.java-config.debug-options="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${DEBUG_PORT}"
Don't forget the double quotes, and no spaces around the equals sign!
3. Set the instances' debugging ports
In this case we have 2 instances, i1 and i2. We will make the debugging ports 11111 and 22222 respectively:
asadmin set i1.system-property.DEBUG_PORT=11111
i1.system-property.DEBUG_PORT = 11111
asadmin set i2.system-property.DEBUG_PORT=22222
i2.system-property.DEBUG_PORT = 22222
That's it. You're ready to debug multiple instances.
This post brings about the powerful feature of "tokens" in GlassFish management!
Posted by Kedar on April 25, 2007 at 08:34 AM PDT #
Posted by Joe Fialli on June 25, 2007 at 01:31 PM PDT #
Posted by Kedar on June 25, 2007 at 01:37 PM PDT #
Really useful blog!. Thanks!
Posted by Venu on March 17, 2008 at 11:57 PM PDT #