Java Tip 78: Recycle broken objects in resource pools

Here's how to improve performance and share objects between clients with the recycler idiom

1 2 Page 2
Page 2 of 2
  • Is an object pool being used? This indicates that resources are tight and particular resources should be shared, or that creating the resources takes considerable effort.

  • Will the composite object take a long time to create, due to the high cost of constructing all of its components?

  • If a builder pattern is appropriate for creating the objects, it is possible that recycling may also be appropriate, since it depends on a level of complexity that can warrant the overhead of its use?

  • Will testing the parts of an object take less effort than recreating those parts? Again, as parts become more complex, the utility of recycling becomes greater.

  • Is there reason to believe that objects will break often enough to justify the programming effort to make them recyclable?

There are a multitude of variations on the object pooling and recycling theme, and we have attempted to outline some of the possibilities. If you find that any variations on, or derivations of, these themes are helping you to produce effective Java servers, please let us know.

Philip Bishop is an independent distributed object consultant specializing in the design and implementation of Java and CORBA systems. Nigel Warren is a director of armillary research and design. Both authors have been consulted by many international companies on object-oriented systems design, and are the authors of Java in Practice: Design Styles & Idioms for Effective Java, published by Addison Wesley.

Learn more about this topic

1 2 Page 2
Page 2 of 2