Adam Bien's Weblog

Tuesday Feb 02, 2010

Object Pooling Can Be Still Useful - For Entirely Different Reasons

Pooling was initially introduced as a tuning action for the slow performance of object creation and garbage collection in particular. On a modern JVM > 1.4 pooling is no more needed for the optimization of memory management in a typical business application. It can even have a negative effect on the garbage collector performance. In special cases, like creating millions of instances in every method call, it could still pay off. 

Instance pooling, however is still interesting for objects with slow custom "post construction". In some cases you want to inject some dependencies after the object creation, read some configuration etc. This can be slow and doesn't have to be performed over and over again. In such cases object pooling will improve the overall performance. 

Instead of prematurely optimize your application, I would rather build the simplest possible thing and measure the performance continuously (e.g. with VisualVM). In most cases you will be surprised where the actual bottlenecks actually are. 


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Kommentare:

This assumes that you have to create new instances all the time - a Singleton based solution like Spring does not need this as only one instance will be created anyway.

Gesendet von Eberhard Wolff am February 02, 2010 at 10:36 AM CET #

@Eberhard Wolff This does not work well in situations where the state of the instance should be saved.

Gesendet von Mateus Bicalho am February 02, 2010 at 02:08 PM CET #

Senden Sie einen Kommentar:
  • HTML Syntax: Ausgeschaltet
Interviews/About
My Recent Book
Java One 2009
CommunityOne East N.Y.C
JavaONE 2008 Interview
Search
...the last 150 posts
...the last 10 comments
greenfire.dev.java.net
Links
my.netbeans.org
Visitors
License