One of our web application was running out of memory recently. Today I finally managed sometime to dig in. First job was to look for a profiler, turns out, there is a cool java profiler named visualvm, it’s free and it now comes with JDK! After configuring it with eclipse and profiling my local tomcat for a while, I realized the easiest thing would be to simply get a thread dump from production and analyze that.

Again, after Googling for a while, I realized that there is a simple utility called jmap that also comes with JDK and let’s you take memory dump. Cool, eh? So here’s the command –

jmap -dump:format=b,file=heap.bin 5796

Here heap.bin is the name of the output file and 5796 is the tomcat process id. It looked pretty simple, all I had to do was run the command, then download the bin file and open it in visualvm. But it never is as simple as it appears, isn’t it? 🙂 When I ran the command in my production server, I got the following error –

“Not enough storage is available to process this command”

At first it seemed like I don’t have enough storage or memory. But again, after Googling, it turns out you can’t run that command when you Remot Desktop to your production server. The solution was to remote login usign the following command –

mstsc /admin /v:SERVER

I am not sure why, but once I logged in using the /admin parameter, I was able to run the command and take the heap dump that I was after. I’m downloading the file as I write this blog, next step is to find out who’s eating my pie! 🙂


I have had an opportunity to play around with annotation and hibernate validation. Basically, hibernate has a few predefined annotations that you can use to annotate your getter methods. Later on, when in comes the user input, it will be validated based on the annotation type you use. For example –

@Length(max = 100)
public String getEmail() {
  return email;

Here we are limiting the length of the String and also annotating it as an Email. The @Email annotation has a Validator class defined with @ValidatorClass annotation. The isValid() method of the respective validator gets called at runtime which then decided whether the input value is valid. You can find out more about it here.

Anyway, my problem in the above email field was, now we wanted to save multiple email addresses separated by comma. Since the default validator treats the whole value as one email address, it discards the input when there is a comma, obviously. Therefore, we needed a custom solution. After a bit of research and code digging, the final solution turned out to be very simple. But more importantly, elegant as well.

To implement custom validation in hibernate, all we need to do is define a new annotation and a corresponding validator. Lets first create the annotation.


public @interface CustomEmail {
  String message() default "Email address not valid";

As you can see, our annotation is called CustomEmail (as opposed to Email in the first listing). We have written a new class named CustomEmailValidator and defined it here as our validator class. This class implements  org.hibernate.validator.Validator which has a isValid method that will get called at runtime. All we needed to do was put our validation logic inside this method. Here is a part of the code

public class CustomEmailValidator implements Validator<CustomEmail>, Serializable {

  public boolean isValid(Object value) {

    // return true or false after validating value


Note, while implementing the Validator, we have to define the annotation name that this validator is linked with. Thats it! We just created implemented a new validation rule using hibernates validator framework.

Just came across this Garfield post today through google gadget. As always they are funny as hell. But wait, this one is more. It looks awefully familiar !

Garifield Sleeping

Can you guess which one is me?

Business as usual?

For the past couple of days, I have been trying to deploy the web services I have written. It was a lot harder than I ever imagined. I had configured everything and it was running fine in my local setup. I took my time and made the perfect deployment plan. It was supposed to be just a matter of updating the context followed by a restart of the application server. Needless to say, it was nowhere near that!

It is a matter of great discomfort when you are deploying a set of new configurations, which works perfectly in your local box, refuse to work in the live server. To make matter worse, the error doesn’t give any clear indication and the log file behaves like just another day in the office!

Fortunately though, the air has cooled down, all the issues are resolved now at the expense of couple of  days of frustration and head scratching debugging.

My collegue yesterday noticed I was unusually quite (even for my standard) and wondered whether this sort of problematic patch is frequent in programming. Frequent or not, the aftermath is surely worth it and more. 🙂

Last evening was special for me. I have always wanted to go to those fancy car shows. Watching pictures of others in front of Ferrari or Mercedes seemed very appalling to me. Well, I was never going to miss when this opportunity came to me. There is a motor expo going on at the moment and we happened to be there last evening. We went there after office and stayed almost till 9 PM. For me, it was an amazing experience. I don’t know why, but I was extremely delighted to be there. I even managed to totally forget my headache the whole time I was there!

I saw the cars – as much as I could – literally. The best part of course was watching the red Ferrari. But there were a lot of other cars for the pleasure of my eyes. Well, yes eyes. I wasn’t thinking about buying, duh! And I don’t really day dream either! 🙂


The main attraction though, was the future car from Mazda –

Mazda Taiki - The Future Car

Mazda Taiki - The Future Car

This beautiful two seater was designed with a single objective to “create a design that visually expresses the flow of air.”

There were also great cars from Lamborghini, Lexus, Toyota, Holden, Maserati, Nissan, Renault, Suzuki, Volvo, Ford and Hyundai. To find out more about the expo and see other car pictures, visit the official site.

Obama in Xbox

Like millions others worldwide, I am also quite keenly following the developments of US presidential election this year.  I was amused to see the following today – Obama’s campaign has put adverts on Xbox live game ‘Burnout Paradise’. Looks like he is trying to encourage young voters to sign up.

Barack Obama in burnout

Barack Obama billboard in Xbox

I have a new toy!

I can’t remember when was the last time I was so happy after buying something. Maybe not since the old and naive childhood days when a toy used to mean everything I could ever hope for! Well, last night we just got ourselves a cute little Car. After getting it from its previous owner we went for a quick spin around the block – it was fun and kind of scary! For the first time I was driving without an instructor. My wife tried her best to chip in with helpful instructions though.
I had given our car space to our neighbour for this week, therefore had to park the car on the street last night. Its quite a normal thing to do, but being the first day, I was very nervous for doing that. Have I locked the car right? Have I blocked any drive way? Why is a light flashing there? I also remember jumping out of the bed twice and looking out of the window to check if the car was there. Not my fault, I heard a car door closing sound followed by start of an engine! 🙂
Anyway, this is how it looked this morning from our window –
Our first car

Our first car