Tuesday, July 15, 2008

JDK6 comparing with JDK1.4.2

Again a comparison and reason why JDK6. Weeks back one of our team member gave a presentation on JVM performance improvement in Mustang. I have just collected a useful point here and try to compare with older JDK version. Here is the code:

import java.util.*;

public class RuntimePerformanceGC {

public static void main(String[] args) {
RuntimePerformanceGC ob = new RuntimePerformanceGC();
Vector v = new Vector();
java.util.Date now = new java.util.Date();
long t1 = now.getTime();
ob.addItems(v);
java.util.Date now1 = new java.util.Date();
System.out.println(now1.getTime()-t1);
}
public void addItems(Vector v) {
for(int i =0;i<500000;i++)
v.add("Item" + i);
}
}

And the output in ms is:

JDK1.4.2: 984

JDK 6: 578

You can see a massive difference. 37 percent improvement in time. Why ? Here goes :

This is because of Runtime Performance Optimization. The new lock coarsening optimization technique implemented in hotspot eliminates the unlock and relock operations when a lock is released and then reacquired with no meaningful work done in between those operations. And this is what happening in our example. Since, Vector do thread safe operation, it takes the lock for add, release the lock and then takes it again.

So, I just tried to give one more reason why use JDK6 ;-). This is off course not the only reason for big improvement, I will try to cover some more in upcoming blogs :-)

2 comments:

Unknown said...

Hi

I am using 4 JPanels in my application, i am adding 3 panels to a 1 Main Panel of my application.

when my code was in JDK1.3 i was able to set focus and key listeners properly

but after upgrading to JDK1.4.2, focus is not working, key inputs are not captured on jpImageDisplay add as follows:
jMainPanel.add(jpNaviLogoMain,BorderLayout.EAST);
jMainPanel.add(jpImageDisplay,BorderLayout.CENTER);
jMainPanel.add(jpImageTxt,BorderLayout.SOUTH);

Please help

Vaibhav Choudhary said...

Problem looks little wired. Can't help you with this much of knowledge. Good if you can share the code. I have never seen such a problem with 1.4.2

Also, try out with other layout.