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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.