Dead Glassfish Connections

Running a complex web application with sessions and connections to the DB, MQ and HTTP clients brings you sooner or later into a discussion or problem with connections that have not been properly terminated by Glassfish or the client. Depending on the time-out settings in the OS and in Glassfish you might face CLOSE_WAIT connections. What is causing this is topic by itself, also helping the system to get rid of it. At the end quite likely the problem lies somewhere in the sourcecode.

In my case we found a large number of CLOSE_WAITS to Glassfish with strange IP addresses (closed enterprise app but open to public web).

Here only some helpful scripts (Linux/Ubuntu):

Find the Glassfish PID

jps | grep ASMain | awk '{ print $1 }'

#get it into variable
pid=$(jps | grep ASMain | awk '{ print $1 }')

Show all socket connections

netstat -anp | grep ESTABLISHED
netstat -anp | grep CLOSE_WAIT

Show all connections to Glassfish

netstat -anp | grep CLOSE_WAIT| grep $(jps | grep ASMain | awk '{ print $1 }')
netstat -anp | grep ESTABLISHED| grep $(jps | grep ASMain | awk '{ print $1 }')

Still a bit hard to review



Now lets sort by IP and count it (ignoring the ports)

netstat -anp | grep CLOSE_WAIT| grep $(jps | grep ASMain | awk '{ print $1 }')|awk '{print $5}'|awk -F':' '{print $1}'|sort -k1|uniq -c

Creates a list like this (number of connections and the related ip address)

netstat summary

netstat summary

You can pack this int a cron job or even get it combined with a geolocation webservice to find the user.


Getting started with Drools and Netbeans

Rule engines are a rather complex topic with potentially a steep learning curve. I am looking at a few options, Drools being one of them. As usual one can read all the theoretical papers, but rather I have a something to look at and play with fast. Ultimately I need to integrate the rule engine into my application, so I dont want to play with eclipse editors for rules but seeing a rule engine ticking inside my Netbeans project. I found one tutorial from Vishal Akhouri which I updated to the latest version of Drools and some minor fixes. Most of the sample source code is from Vishal.



Update DynDNS hosts with Java and HttpComponents

I was looking for a way to update the DynDNS hosts pointing to my EC2 instances that run only on demand (controlled by an web application). Yes, there are apps and tools to let the server itself update his DynDNS hosts, but I want to do it from a central application. The DynDNS API description you find here, unfortunately there are no samples. But if you familiar with REST calls, shouldn’t be a big issue. For those who to get running quick, here the key code. To experiment, just create a simple Java application with Netbeans (or any other IDE), download the HttpComponents from Apache and add the library files to your project.



Sourcecode to update an IP address

void updateDynDNS() {
// replace with your own data !
String hostName = "";
String hostIP = "";
String userName = "user";
String userPassword = "password";
int responseCode;

try {

// Encode username and password
BASE64Encoder enc = new sun.misc.BASE64Encoder();
String userpassword = userName + ":" + userPassword;
String encodedAuthorization = enc.encode(userpassword.getBytes());

// Connect to DynDNS
URL url = new URL("" + hostName + "&myip=" + hostIP);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("User-Agent", "Demo DynDNS Updater");
connection.setRequestProperty("Authorization", "Basic " + encodedAuthorization);

// Execute GET
responseCode = connection.getResponseCode();
System.out.println(responseCode + ":" + connection.getResponseMessage());

// Print feedback
String line;
InputStreamReader in = new InputStreamReader((InputStream) connection.getContent());
BufferedReader buff = new BufferedReader(in);
do {
line = buff.readLine();
} while (line != null);


} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);


Up to you to embed into your application and do proper exception handling.

In a separate tutorial I will describe the basics of an EC2 controlling application using the AWS SDK for Java.

JavaFX Composer Out !

I was not looking at JavaFX for a few months and the latest rumors on the potential death of the RIA product under the new owner did not make me spend time learning more, even I believe it might be the missing piece for some boring Java (Swing) enterprise applications. Yesterday the plugin that finally supports the visual creation of JavaFX was released. (Go for plugins,reload catalog and select the version 1.0 of JavaFX plugin)

JavaFX Plugin

Once the download is finished you can start creating JavaFX applications

New JavaFX Project

JavaFX Skeleton Project

I cant judge yet the composer or rather non-manual (full control) way to create a fx stage. The composer creates the code (similar to Swing) in the background and you cant touch it without screwing the fx file. I will try on a few samples.

First Remark: The preview pane renders useless now, it does not work with the composer anyway.

More infos on the JavaFX Composer

Netbeans 6.8, Glassfish V3 and JavaEE6 released

The waiting is over, finally we get our hands on a production release of EE6 and Glassfish V3. Last week (Dec 10th) released, you also get it together with Netbeans 6.8. There is lot of attention and coverage on the latest version of the enterprise platform, so I spare you from my personal views,  though I was really looking forward to use it beyond previews and beta’s. I am excited to work with the matured and now “rightsized” framework. Time to get active on writing tutorials and books.

Some useful links with more details:

Jazoon 2009: Day 3

Last day of this years Jazoon.

  • The Android Runtime Environment by Joerg Pleumann from Noser Engineering (which contribute a lot to the Android codebase)
  • Android Application Model by Dominik Gruntz
  • Ed Burns on JavaEE and JavaFX integration. Entertaining and interesting as usual. Thanks Ed !
  • Daniel Seiler on the ZK Ajax framework. Thanks for the confirmation of my choice of framework.

My final resume and feedback:

  • A very good location in terms of conference room quality, since this is a movie theatre with great accoustic and projection.
  • Good mix of topics and tracks. Anyone who is doing something with Java will find his cup of tea (eeer.. Java).
  • Some “famous” folks to get hands on them and discuss face to face.
  • As in all conferences: some speakers cannot present. Sorry to say so. It is boring to read slides with tons of text.
  • Not enough wireless “plugins”. Seems some of the attendees were operating datacentres during the conference and hacking away during the whole time. Thanks for not sharing wireless space.
  • Maybe a bit too expensive, but location, catering and speakers cost money I guess.
  • I will join this event again next year.