Usnig Session as an Instance Variable

Many of my servlet's methods use HTTPSession. Is it thread safe to declare an HTTPSession variable as an instance variable?

0
source share
2 answers

Using defaut, Servlets are not thread safe . Moreover, a servlet instance will be called for many clients. It is absolutely wrong to have a session as an instance variable.

Link:

Is safe for servlet

Create thread-safe servlets

+2
source

No, this is not safe. when the application starts, a servlet is created. A servlet has only one instance (this means that multiple requests / clients use the same servlet), so you should avoid any instance variables.

+1
source

Source: https://habr.com/ru/post/1400964/


All Articles