1

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 :)

rachana
  • 3,344
  • 7
  • 30
  • 49
Bhaskar
  • 337
  • 6
  • 21
  • possible duplicate of [static variables, what is their life span?](http://stackoverflow.com/questions/11134686/static-variables-what-is-their-life-span) – Smutje Aug 07 '14 at 06:15

1 Answers1

4

static variable value is set at the class loading.

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

Apart from that manual setting to default by code.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136