简体   繁体   English

Java Web应用程序中的静态用法

[英]Static Usage In a Java Web-Application

Bit of basic question but even after reading loads over net I am clueless about the usage of static for variables in a web-applicaton. 有点基本的问题,但是即使在通过网络读取负载之后,我也不知道在Web应用程序中将static用于变量的情况。

Problem : In my web-application deployed over weblogic, i am declaring a static variable and assigning its value as 0. 问题 :在通过weblogic部署的Web应用程序中,我声明一个静态变量并将其值指定为0。

public static int startIndex = 0;

Now, I am using this variable in my method and making few changes to its value depending on the requirement. 现在,我在方法中使用此变量,并根据需要对其值进行了很少的更改。 My query is, if I make a change in its value say, startIndex=100 , then when will it be assigned back to 0? 我的查询是,如果我更改其值,例如startIndex=100 ,那么何时将其赋值回0? That is, at what point of time will this static variable startIndex will be set back to its initial value? 也就是说,在什么时候该静态变量startIndex将被设置回其初始值?

Is at server rebounce or each time when that class will be referenced in the same session or difference session? 是在服务器反弹还是每次在同一会话或不同会话中引用该类时? Clueless!! 无能为力! Any suggestions would be helpful. 任何的意见都将会有帮助。 Thanks :) 谢谢 :)

static variable value is set at the class loading. 在类加载时设置static变量值。

So whenever the class is loaded/re-laoded ie application (re)deployed, server restart, class reloading by Classloader, etc 因此,每当加载/重新放置类时,即(重新)部署应用程序,重新启动服务器,通过Classloader重新加载类等

Apart from that manual setting to default by code. 除了该手动设置外,默认代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM