10 Replies Latest reply: Apr 14, 2008 11:17 AM by 796440 RSS

    Static object becomes null


      I'm working on a j2ee app, in one of my classes i create a static object that stores some values. The problem is that sometimes the object becomes null and the app starts to crash.
      public class PesquisaUtente extends BasicServlet {
      private static TabelaConfig cfg;
      public void executaActions() throws IOException {
      if (cfg == null) {
      //(...) here, I call a lot of other functions
      String value = cfg.getValue("param");
      The cfg object only get initialized/changed in the begining of the execute function, nowhere else.
      The iniciaTabelaConfig(); takes a bit of time, so I would like it if it would not be executed more then once, but some time after Tomcat starts (usually a few days) the cfg object becomes null.
      Why does this happen?
      Shouldn't the fact that it is static ensure that the value remain unchanged?