Sub-class ActionServlet and override the init() method.

Also a good idea to override the destroy() method to clean up allocated
resources. Additionally the reload() method does the destroy and init
actions to re-load the servlet.


  public void init() throws ServletException {
     super.init();
     initMyClass();
  }

  public void initMyClass() throws ServletException {
     MyClass myClass = new MyClass();
     getServletContext().setAttribute("myPackage.MyClass", myClass);
  }

  public void destroy() throws ServletException {
     super.destroy();
     destroyMyClass();
  }

  public void destroyMyClass() {
     // clean up allocated resources here
  }

  public void reload() throws IOException, ServletException {

     super.reload();

     // Shut down
     destroyMyClass();

     // Restart
     initMyClass();
  }



-----Original Message-----
From: Jeff Trent [mailto:[EMAIL PROTECTED]]
Sent: 08 May 2001 15:52
To: [EMAIL PROTECTED]
Subject: Application Scoped Object Initialization


What is the suggested method for singleton, application scoped object
initialization?  Where & how does it happen?

I want to create a singleton containing shared cached lists to be used in
populating html:options with.

Thanks.

Reply via email to