Java Performance Tuning

Java(TM) - see bottom of page

|home |services |training |newsletter |tuning tips |tool reports |articles |resources |about us |site map |contact us |
Tools: | GC log analysers| Multi-tenancy tools| Books| SizeOf| Thread analysers|

Our valued sponsors who help make this site possible
JProfiler: Get rid of your performance problems and memory leaks! 

Training online: Threading Essentials course 

Newsletter no. 16, March 25th, 2002

Get rid of your performance problems and memory leaks!

Java Performance Training Courses
COURSES AVAILABLE NOW. We can provide training courses to handle all your Java performance needs

Java Performance Tuning, 2nd ed
The classic and most comprehensive book on tuning Java

Java Performance Tuning Newsletter
Your source of Java performance news. Subscribe now!
Enter email:

Training online
Threading Essentials course

Get rid of your performance problems and memory leaks!

Thanks for those of you who have already voted for my book "Java Performance Tuning" in the JDJ readers choice awards. To those of you who find the website useful and haven't yet voted, I encourage you to vote for my book. The website is a companion to, and a direct consequence of my book.

If anyone is interested, I'll be giving a talk in London, UK, on April 18th, on managing J2EE performance. You need to register if you feel like coming along. But I understand places are filling up quickly so don't leave it too late to register.

Now, on to this month's news. I've added 4 new category pages to the website: tips about using final; tips about EJBs and a sub-page for those tips relating to EJB design; and tips for those creating webservices.

This month we list a flurry of articles on low-level tuning (microtuning, GC/heap, string, I/O, and more), a variety of J2EE tuning articles, mainly EJB but also JTS and JMS. We list more J2ME articles; a comeback for graphics programming tips, the first for a couple months; and many more articles.

New articles are still appearing at such a rate that I have no time at all to get to my backlog of older articles. I've even had to put some current tutorials into my backlog. A couple of months ago I delivered a newletter where I characterized the month as belonging to design patterns. One thing I find interesting is that several of the articles this month are not about design patterns but include them almost offhand. Even though design patterns have been around for years now, two months ago articles mentioning design patterns still felt the need to explain what they are. Now just a couple of months later, the articles assume you know the basics, and almost in passing mention which pattern is being used and what its functionality is.

Kirk discusses load balancing, as well as continuing his usual excellent roundup of the interesting performance discussions over the last month. This month, Kirk includes discussions from a new Java performance discussion list at javadevtalk.

Also this month a new columnist, Javva The Hutt, joins us to talk about performance related matters. Any relation to the similarly named Star Wars character is, I am assured, entirely non-coincidental. Javva is probably previously best known for his incisive but unpublished analysis of how different toppings affect the aerodynamic performance of pizza based frisbees.

If you feel this newsletter could be useful to a friend, why not send them the URL. Note also that Yukio Andoh's Japanese translation will hopefully be available at in a while.

A note from this newsletter's sponsor

Precise Software revolutionizes J2EE Application Performance
Management with automatic problem detection & correction. Read
our white paper on how to instantly isolate J2EE bottlenecks.

J2EE Performance Master Class

Are your BEA Weblogic/ IBM WebSphere applications running at full throttle? Register now to attend our Free J2EE Performance Master Class, 18 April in London. Please join Jack Shirazi, author of "Java Performance Tuning" from O'Reilly, and J2EE experts from Precise Software Solutions to learn how to improve the performance of your web and J2EE based applications.
To register, click here or call Becky Lunn on 01223 716660.


Java performance tuning related news.



Recent Articles

All the following page references have their tips extracted in the tips section.

Older Pages

All the following page references have their tips extracted in the tips section.

Jack Shirazi

Kirk's roundup

Throughout my career in the IT industry, I?ve been shown many different techniques to efficiently utilize redundant computing resources. In fact, I?ve even contributed to the fray by writing a few myself. Every single technique (including mine) were called load-balancing algorithms. But, was it correct to label them all as load balancing? And if not, what should they have been called. Well, as it turns out, in many cases, these techniques (including, gulp, mine) only distributed load. What?s the difference you ask? From a server's perspective maybe, not a lot. But, from a user's perspective, the difference can be quite significant. It all comes down to one important metric, response time. To demonstrate this, lets go back to my experiences with airport security at Charles du Galle (CDG) in Paris.

CDG's security stations have a very unique queuing system. If any of you have been through CDG, then you?ll know what I mean. The queue to each security station is designed in such a way that you cannot tell how long the queue is, nor can you easily escape once you?ve made your choice of queue. In general terms, the response time that I experience is a composite of my service time at the security station and the sum of the service time of everyone else in front of me. In other airports, once I?ve entered a queue, I can jump to another queue if I feel that this move will improve my response time. One cannot do this at CDG. In CDG, the physical layout of the queues reduces the problem to a single queue, single server scenario. Even though entrances to other security stations at other airports also appear to be a single queue, single server scenario, it is possible for you to jump queues allowing the system to achieve a moderate amount of load balancing.

Both of these types of security queues are a far cry from the single queue multiple server experience that I have at the ticket counter within airports. And since I?m a frequent flyer, I often get to stand in the priority queue. In this regard, I'm generally quite happy about the response times I experience.

So, how does this help with the question of what is load balancing and what is load distribution? It all comes down to this; load balancing is intelligent load distribution. In other words, I?m going to try to queue up to the the server who is currently under the least load. Since the queues at CDG offer me no clues as to how long I might have to wait, it models a simple load distribution system. At other airports, when I can see that the line to one security station is short, I can use that information to effect an intelligent balance of the load on the system.

Clearly the system at the ticket counter gives the fairest share as individuals all wait for the first available server. And as an added bonus, a priority queue is available to ensure good response time for those more important tasks. So, the next time you look at a load balancing system, ask the question: which line should I stand in?


The month we start the round-up with, a site started by Chris Wells, Paul Oehler, Anthony Eden, Dustin Williams and Riyad Kalla (whose photo bears a striking resemblance to Homer Simpson). Each Java discussion group has taken on it?s own personality and, true to form even with it?s short existence, so too has javadevtalk. I recommend that you all meet the new kid on the block.

We start with a thread discussing string comparison. The initial code

int i=0;
while (string1.substring( i, i+1).equals(string2.substring( i, i+1))) {
return i;

was condensed to

int i;
for(;string1.charat( i) == string2.charAt( i); i++);
return i;

While one participant responded that one should consider using the new regex feature in the JDK1.4, this might be a heavy implementation for such a simple search. One other point, if string1.equals(string2) == true, both implementations will throw a StringIndexOutOfBoundsException which is probably not desirable.

In an attempt to stir up a good conversation, the moderator posted a topic with the title "Avoid SWING when you can". The argument is quite detailed and the responses are quite thoughtful. As such, it is best that they not be summarized here.

The JavaRanch

Treading over to familiar turf, lets see what?s happening at the Salon. In the category of are we worrying about the right thing, we can find a question asking about the differences in memory usage between the subclass and containment relationship between two objects. The answer is: yes of course there is a difference in the amount of memory used to represent each relationship. The real problem is that each of subclass and containment notationally express an important design features. Don't ignore this important distinction for the sake of saving a few bytes of memory.

The question of using importing * was raised once again. Since * is used as a notational convention that does not survive compilation, it has no effect on performance. Having said this, using * can affect readability and hence understandability of source code. For instance, if you import com.mycomp.mypackage.*, others who may have to read the code may not be able to easily understand which classes are being used.

In another thread, the poster found that his GUI performance was less than optimal. He was looking for recommendations which tool to use to help fine tune the application. One response was to compile using the -O option. The bartender stepped in and pointed out that the -O is ignored. Why is -O ignored? Here?s an opinion from the Ant developers list. The JDK 1.3 compiler was completely re-written from scratch. Since Hotspot was included by default in the JDK 1.3, the authors felt no need to add an extra layer of code for optimization purposes. This does not say that this will change in the future.

Moving on to we find an interesting thread where WORA seems to break down which results in a performance problem for our gaming friends. The story starts when a gamer comments that he cannot use the keyboard because the key press appears to be broken in Linux. Further discussion leads to the discovery that it may not be a problem with the VM but the behavior is typical to the way Linux functions. The VM must rely on the OS to provide it with key events. Of course, this behavior is specific to each platform. In the end, there is a suggested work around. This does point out the importance of testing your application on all intended target platforms.

The Server Side

Finally, lets visit to see what?s being talked about there. It was pointed out that there is a .net implementation of the pet store application at For those familiar with java pet store, this maybe a good introduction into .net.

Next to this was a posting questioning the techno speak "the application/architecture should be scalable". Fair question, just what does this mean? I?ll combine two answers to see if we can come up with an answer. A scalable application will maintain a stable performance profile under load. When load strains the underlying hardware, a scalable architecture will allow the application to maintain a stable performance profile as the capacity of the underlying hardware is increased.

The question of entity bean scalability continues to be a hot topic. As EJB technology matures and developers become more familiar with it, one would hope that techniques that aid performance would be developed. Again this month there are more threads regarding EB scaling. The questions of how to scale or will it scale keeps being asked. The posts that claim that EB do scale never offer any real clues on how to develop scalable EB systems. Witness this response.

"You need to know what you're doing. If you do not have any experience and if you don't dare to even open a book on J2EE, then you'll most likely fail."


One final note on the subject of load distribution, what follows is a true story as related to me. "As I approached the security station at Hartsfield (Atlanta?s airport), I was directed to one of the queues by a blind person. The person used round robin to direct people to one of the several queues. He was oblivious to the number of people in the queue. Since the queue he pointed me to was very long, I ignored him and went to a shorter one." The point here is not to make jokes about the blind employee. I?m sure he was doing his utmost to carry out the task assigned to him. More to point is that people ignored his direction because they had better information than he did. The real question is, if these people decided against round robin in the real world, then why is it used so often in the world of computing?

I do owe a note to BEA?s WLS team as just as my last round-up went to press, they published ECPerf results. Not to be outdone, IBM announced results on March 13th. The measurements show WebSphere rates at $13/BBops and WebLogic runs in at $18/BBops. Details can be seen at

Kirk Pepperdine.

Javva The Hutt

How did I get here? Ah, one of the great existentialist questions. In my case, I can answer it. Our Great Leader (OGL) asked me if I'd like to write a column for his website newsletter. "Something related to Java performance" he said. "How about if it's related to Java, and I write it real fast?" said I. Ever noticed how email doesn't let you see someone's reaction?

No bottlenecks, but its slow

OGLs website provides a huge list of tips to make your Java app perform faster. I could have used these tips years ago to avoid severe embarrassment. I was once looking for the bottleneck in a bank middleware app. The head of the project swung by one night when there was just me and another nerd playing with the server. "How is it going?" he asked. After the usual round of blah blah blah, we got down to what he really wanted to know: where was the problem?

"Is it I/O?" came the first question. "No" said I, having definitely identified that the disks were under-utilized and that there was no problem with paging. "Memory then?" he asked. "No, we've still got lots of spare RAM" I answered. "Ah, so it's swamping the CPU." he said.

Now, I was working for a middleware app vendor. If it was bottlenecking on the CPU, it was going to have to be an application problem or else my real boss was going to be real unhappy. But I hadn't been able to find an application bottleneck yet. Heck, I hadn't found any bottleneck yet. This was quite a few years ago, Java was relatively new and the state of profiling tools was quite basic. And the state of my profiling knowledge was also quite basic. So I stupidly replied "no, its not the CPU, I haven't found any bottlenecks yet".

In case you haven't thought it through, an application which has no I/O bottleneck, no memory bottleneck and no CPU bottleneck takes no measurable time to run. Or at least it's fast enough that it doesn't need someone sitting at a workstation for days trying to find out why it isn't fast enough. I kept my job, but I never managed to lose my ability to make stupid statements.

Anyway, I did some hard thinking, and fiddled a bit and finally worked out that garbage collection (GC) was taking ugly amounts of time. It hadn't shown up in the method profiling, or at least I hadn't recognized it then if it had. Nowadays, the first thing I look at is GC. Hopefully, OGLs website will help me avoid looking stupid in the future sometime, when some obscure new bit of Java isn't performing and I don't know why.


Speaking of obscure Java, I found this tip in OGLs tips page:

"The -Xoptimize flag seems to improve performance on those 1.2.x JVMs that support it."

What the? Where did this -Xoptimize option come from? It sounds like it could be pretty useful. So I tried to track it down. Info was real sparse. The originating doc said this:

"Note that the -server option in Java 2 SDK 1.3.0 is equivalent to the -Xoptimize option in Java 2 SDK 1.2.2. The -server option is recommended for all server-side applications, and is especially useful in optimizing CPU-intensive code."

But my 1.3 and 1.4 JVMs all recognize the option. Is it just a psedonym for -server? The Sunsite 1.2 release notes say

"The virtual machine (VM) in version 1.2.2_11 (and prior versions) of the Java 2 SDK, Standard Edition, recognizes the experimental -Xoptimize command-line option. Future update versions of the Java 2 SDK 1.2.2 will not have the -Xoptimize option, and the use of this flag is strongly discouraged. Performance results using this flag have been very mixed, and there have been failures associated with its use."

And finally, the sun answer book says

"(SPARC only) Experimental only. Spend more time optimizing methods in the JIT. This option will most likely benefit long-running CPU-bound applications and might result in increased performance of your application."

Seems like it is the -server option, only not stable in 1.2. Well at least now I won't look stupid if someone asks me about the -Xoptimize option. [You might not sound stupid, but I'm not sure about the look - ed.]


I was flicking through some of the Sun guys home pages. Bill Joy's listed Peter Deutsch's "The Eight Fallacies of Distributed Computing" which I brought to the attention of OGL. I think he's putting it into his tips list for this month. So I was thinking, have we got great fallacies of Java? How about these for starters

Send me your suggestions. I'll compile them and report back sometime in the future. Oh, and try to keep them clean. I know some of you have furtive imaginations.


Javva The Hutt.

Microtuning (Page last updated March 2002, Added 2002-03-25, Author Jack Shirazi). Tips:
JMS redelivery (Page last updated March 2002, Added 2002-03-25, Author Prakash Malani). Tips:
Caching SOAP services (Page last updated March 2002, Added 2002-03-25, Author Ozakil Azim and Araf Karsh Hamid). Tips:
String concatenation, and IO performance. (Page last updated March 2002, Added 2002-03-25, Author Glen McCluskey). Tips:
Sun community chat on EJBs with Pravin Tulachan (Page last updated March 2002, Added 2002-03-25, Author Edward Ort). Tips:
Double-if on multi-CPU (Page last updated February 2002, Added 2002-03-25, Author Phil Vickers). Tips:
Stateful to Stateless Bean (Page last updated February 2002, Added 2002-03-25, Author Brett McLaughlin). Tips:
Alternatives to using 'new'. (Page last updated March 2002, Added 2002-03-25, Author Jonathan Amsterdam). Tips:,3658,s=708&a=23125,00.asp
Tuning JVMs for servers. (Page last updated February 2002, Added 2002-03-25, Author Timothy Dyck). Tips:
Object Resource Pooling (Page last updated March 2002, Added 2002-03-25, Author Paul King). Tips:
Using NIO (Page last updated March 2002, Added 2002-03-25, Author Aruna Kalagnanam and Balu G.). Tips:
J2EE best practices. (Page last updated February 2002, Added 2002-03-25, Author Chris Peltz). Tips:
MIDP GUI programming (Page last updated March 2002, Added 2002-03-25, Author Qusay Mahmoud). Tips:
The Eight Fallacies of Distributed Computing (Page last updated 2000, Added 2002-03-25, Author Peter Deutsch). Tips:
Inverting booleans (Page last updated February 2002, Added 2002-03-25, Author Heinz M. Kabutz). Tips:
The Proxy design pattern. (Page last updated February 2002, Added 2002-03-25, Author David Geary). Tips:
Java Transaction Service (Page last updated March 2002, Added 2002-03-25, Author Brian Goetz). Tips:
High performance graphics (Page last updated February 2002, Added 2002-03-25, Author ?). Tips:
Minimizing bytecode size for J2ME (Page last updated February 2002, Added 2002-03-25, Author Eric Giguere). Tips:
GC performance tuning (Page last updated February 2002, Added 2002-03-25, Author Alka Gupta and Michael Doyle). Tips:

Jack Shirazi

Last Updated: 2018-11-28
Copyright © 2000-2018 All Rights Reserved.
All trademarks and registered trademarks appearing on are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
RSS Feed:
Trouble with this page? Please contact us