Scalability and Performance Hints
In this chapter, we've focused on the essentials for building and using servlets and paid some attention to their general efficiency features. In this section, we explore some specific architectural suggestions targeted at optimizing scalability and performance.
Use Fine-Grained Serialization
For maximum concurrency, make sure your servlet code is thread safe. However, as we discussed earlier, sometimes this just isn't feasible. In such situations, you have three options, presented in order of their granularity:
Implement the SingleThreadModel interface.
Synchronize methods as necessary.
Synchronize code blocks ...