<分区>
我需要在应用程序运行时共享信息;如果我有:
public class example extends HttpServlet
{
Object globalObject;
doGet...
doPost....
}
用户正在通过服务器和对象 globalObject 使用应用程序;如果另一个用户使用该应用程序,是否会与第一个用户共享该对象?
<分区>
我需要在应用程序运行时共享信息;如果我有:
public class example extends HttpServlet
{
Object globalObject;
doGet...
doPost....
}
用户正在通过服务器和对象 globalObject 使用应用程序;如果另一个用户使用该应用程序,是否会与第一个用户共享该对象?
最佳答案
A user is using the aplication through server and the object globalObject; if another user use the application, will share the object with the first user?
是的! 不同的线程可能用于为不同的用户呈现请求,但使用相同的 servlet 实例。所以是的,该变量对所有请求都是通用的。事实上,这就是为什么说我们不应该使用全局变量来确保线程安全
。
关于java - servlet 上的全局变量。对所有 session 是全局的,还是仅对当前 session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24469257/