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 ...

Get Building Scalable and High-Performance Java™ Web Applications Using J2EE™ Technology now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.