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 |

Our valued sponsors who help make this site possible
Learn to easily find and fix Java Memory Leaks! Read a New White Paper 

New Relic RPM - The Revolution in Java Performance Management is Here! 

ManageEngine: Monitor Java EE Transactions, App Servers, JMX, DB @ $795! 

Question of the month: The effectiveness of object pooling August 2003

FOR A LIMITED TIME!
TheServerSide Java Symposium 3/17-3/19 Las Vegas - $200 off: code JAVA2

JProfiler
Get rid of your performance problems and memory leaks!

JHawk - Java code metrics
All major metrics. Trial, Standalone, Eclipse and Command line versions.


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

See Your Message Here
You could have your tool advertised here, to be seen by thousands of potential customers

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:


Quest Software
Learn to easily find and fix Java Memory Leaks! Read a New White Paper

New Relic
New Relic RPM - The Revolution in Java Performance Management is Here!

Zoho Corp
ManageEngine: Monitor Java EE Transactions, App Servers, JMX, DB @ $795!


FOR A LIMITED TIME!
TheServerSide Java Symposium 3/17-3/19 Las Vegas - $200 off: code JAVA2

JProfiler
Get rid of your performance problems and memory leaks!

JHawk - Java code metrics
All major metrics. Trial, Standalone, Eclipse and Command line versions.


Back to newsletter 033 contents

Should I use object pooling to avoid objects with a short life?

In the early JVMs, the answer to this was clear cut "yes". But now, even the embedded and J2ME

JVMs can handle short-lived objects much more efficiently.

In their HotSpot FAQ, Sun engineering states that pooling should definitely not be used any more,

that pooling actually gives worse performance with the latest HotSpot engines. This is rather a

sweeping statement. Object pools are still useful even with HotSpot, but presumably not as often

as previously. Certainly for shared resources, pooling will always be an option if the overhead

associated with creating a sharable resource is expensive. And for scaled applications, huge numbers of object creations and their associated garbage collections are still a very significant issue which can be completely bypassed using object pools.

Various recent tests have shown that the efficiency of pooling objects compared to creating and

disposing of objects is highly dependent on the size and complexity of the objects. And in some

applications where deterministic behavior is important, especially embedded applications, it is worth

noting that object pools have deterministic access and reclamation costs for both CPU and memory,

whereas object creation and garbage collection can be less deterministic (you cannot specify when garbage collection will occur, nor for how long it will last).

When recycling container objects, you need to dereference all the elements previously in the

container so that you don't prevent them from being garbage collected. Because there is this

extra overhead in recycling, it may not always be worth recycling containers. As usual for tuning, pooling is a technique best applied to ameliorate an object-creation bottleneck

that has already been identified, not one that should be applied up front. However to facilitate pooling being easily added to an application you should use the factory pattern to allocate the objects. This way you can change the allocation implementation at any time. Use a simple create ("new") with garbage collection reclamation initially for your factory method, then measure performance. If you identify a bottleneck caused by the object creation and garbage collection of a certain set of objects, you can easily change the underlying allocation implementation to use (thread local) pools.

The JavaPerformanceTuning.com team


Back to newsletter 033 contents


Last Updated: 2010-01-31
Copyright © 2000-2010 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other countries. JavaPerformanceTuning.com is not connected to Sun Microsystems, Inc. and is not sponsored by Sun Microsystems, Inc.
URL: http://www.JavaPerformanceTuning.com/news/qotm033.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us