Oracle Blog

Byron's Pointless Ramblings

Tuesday Apr 24, 2007

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!

Another Tip: asadmin get "\*" > afile is handy. You can then grep for 'debug' in the file. I use this technique all the time. What human being wants to memorize this sort of crushing detail?

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: