Many methods of my Servlet use HTTPSession. It is thread-safety to declare HTTPSession variable as instance variable?
By defaut Servlets are not thread safe . And moreover, a servlets instance will invoked for many clients. It is absolutely wrong to have session as instance variable.
Reference:
No, it is not safe. a servlet is created when the application starts. The Servlet has only one instance (which means multiple requests/clients use the same servlet), which is why you should avoid having any instance variables.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.