Name

Overstuffed Session

Mistake

Data with too short or long a lifespan is stored in the HTTP session, leading to excessive memory use and potential loss of important data.

Watch for It When

Data stored in the session is only used in a single request, data stored in the session is used over a long period of time and should survive web server crashes.

Solution

Store short-lived data in request scope. Store long-lived data in the business tier or other persistence mechanism. Make sure that data added to the session is removed when it is no longer relevant.

Get J2EE Design Patterns 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.