In many books, when performance and scalability are talked about, the focus is on raw performance issues, like being able to tweak the bits and bytes. While this type of performance management is important, this book attempts to show how to manage performance using good infrastructure components . Therefore, this book focuses on using Commons libraries that help the programmer write scalable code without having to resort to bit tweaking. There are two very common issues when you're writing scalable code: object instantiation costs and running tasks concurrently.
All programs have classes that are more comprehensive and more expensive in resource terms than simple "hello world" examples. It is simply not possible to expect developers to always write lightweight objects; after all, many business processes require you to manage multiple pieces of data. In those cases, the pooled object comes to the developer's rescue. A pool allows a developer to maintain a number of instances on hand for later usage.
This chapter also showed you how to use some simple profiling techniques, which help you decide which objects should be garbage-collected and which objects should not be.
The other scalability factor is the ability to split the task into execution tasks using a pool of threads. The pool of threads is not a complicated concept or technique; rather, it's a helper class that makes threading simpler. Using threading means that multiple threads can access the same object. Typically, this means that you need to use the keyword synchronize to block specific threads from accessing the same code block at the same time. However, with an immutable object, synchronization is not required. An immutable object is a read-only object that can be viewed , but not changed. If you want to change the state of the object, you use specific operators to create new instances of the object that contain a new state. Immutable objects could become computationally expensive because of the large number of class instantiations . To combat this problem, you use pooled objects and slightly change the design of the classic immutable class.
On the CD The sources to the concepts presented in this chapter are located under the directory [CDROM]/jseng/src/com.devspace. jseng .scalability .