Home

This Chapter
-Chapter 16: Object Caching
-Implementing a Cache
-Summary

Table of Contents
-Introduction
-Chapter 1: Model 2 and Struts
-Chapter 2: Input Validation with Action Forms
-Chapter 3: The HTML Tag Library
-Chapter 4: Input Validation and Data Conversion
-Chapter 5: The Validator Plugin
-Chapter 6: The Expression Language
-Chapter 7: JSTL
-Chapter 8: The Bean Tag Library
-Chapter 9: The Logic Tag Library
-Chapter 10: Struts-EL, Nested, selectLabel
-Chapter 11: Message Handling and Internationalization
-Chapter 12: The Tiles Framework
-Chapter 13: Securing Struts Applications
-Chapter 14: The Config Object
-Chapter 15: The Persistence Layer
-Chapter 16: Object Caching
-Chapter 17: File Upload and File Download
-Chapter 18: Paging and Sorting
-Chapter 19: Preventing Double Submits
-Chapter 20: Early HttpSession Invalidation
-Chapter 21: Decorating Request Objects
-Chapter 22: How Struts Works

Previous
Next

 

Chapter 16

Object Caching

Creating Java objects is relatively more expensive than other operations, and constructing certain objects, such as database connections, is particularly compute intensive. To improve performance, you may want to cache and reuse these objects. For instance, database connection pooling is very common nowadays. With connection pooling, the system creates a number of connection instances and reuse them. Also, a servlet container normally only has one instance for each servlet (except those implementing javax.servlet.SingleThreadModel), and all HTTP requests are handled by the same servlet instance. In addition, objects obtained from JNDI lookup are normally a good target for caching considering that JNDI lookup takes lots of CPU cycles. Note, however, caching add complexity to your application, so you don’t want to cache any object. Also, depending on your approach, there are consequences, such as thread safety.

This chapter discusses object caching through the use of the Singleton pattern.

Previous
Next