Thread-safe Servlets
Identify which attribute scopes are thread-safe:
- Local variables Yes, thread-safe
- Instance variables Not thread-safe
- Class variables Not thread-safe
- Request attributes Not thread-safe
- Session attributes Not thread-safe
- Context attributes Not thread-safe
Since a single servlet instance may be handling multiple service requests at any given time.
Since multiple servlets and /or service requests may try to access a class variable concurrently.
See the quote below.
Since sessions are scoped at the web application level, hence the same session object can be accessed concurrently by multiple servlets and their service requests
Since the same context object can be accessed concurrently by multiple servlets and their service requests
Advertisement