Tomcat:Java 静态变量范围、应用程序还是会话范围? [英] Tomcat: Java Static Variable Scope, Application or session wide?

查看:38
本文介绍了Tomcat:Java 静态变量范围、应用程序还是会话范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java 静态变量是否在使用同一个 web 应用程序的所有会话之间共享,还是每个会话都有自己版本的静态变量?

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

换句话说,Tomcat 是为每个会话创建一组新的类,还是只为整个 Web 应用程序创建一组?

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?

推荐答案

Tomcat 为每个 Web 应用程序创建一个 ClassLoader,即 war-File 或 context.因此,每个 Class 都会为 Web 应用程序加载一次.因此,静态变量在多个会话和请求之间共享.

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.

参考:

这篇关于Tomcat:Java 静态变量范围、应用程序还是会话范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆