简体   繁体   中英

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.

Problem : In my web-application deployed over weblogic, i am declaring a static variable and assigning its value as 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? That is, at what point of time will this static variable startIndex will be set back to its initial value?

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.

So whenever the class is loaded/re-laoded ie application (re)deployed, server restart, class reloading by Classloader, etc

Apart from that manual setting to default by code.

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.

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