Tomcat: Java Static Variable Scope, Application or

2019-04-05 02:03发布

Are java static variables shared across all sessions using the same webapp or does each session gets its own version of the static variables?

To put it another way, do Tomcat created a new set of classes for each session or just one set for the whole web app?

2条回答
成全新的幸福
2楼-- · 2019-04-05 02:12

Static variables are shared across the sessions. Be careful of using static variables.

查看更多
冷血范
3楼-- · 2019-04-05 02:13

Tomcat creates one ClassLoader for each web application, i.e. war-File or context. So every Class is loaded once for the web application. Therefore static variables are shared across multiple sessions and requests.

References:

查看更多
登录 后发表回答