I suggest you to use GetServletContext instead of static class in your servlets to have benefit of load-balancing.

public void init() throws ServletException {

   ImportantLibrary lib = (ImportantLibrary) getServletContext().getAttribute( "important_library_key" );

   if ( lib == null ) {
     lib = new ImportantLibrary()

     getServletContext().setAttribute( "important_library_key", lib );
   }
}

Lib is created and put in context only the first time.


Andy wrote:
[EMAIL PROTECTED]">
 
You should put it in tomcat's lib (not your webapp's) if you want it universally available to all webapps (one with tomcat).  You probably cant make tomcat load it but you could make all your servlets by perhaps inheriting from HttpServlet and adding an static reference.

Meaning
public class MyNewServletWhichLoadsThisOnlyOnce extends HttpServlet
{
    static ImportantLibrary myImportantLibrary = new ImportantLibrary();
...
}

all your servlets should extend from MyNewServletWhichLoadsThisOnlyOnce

replace ImportantLibrary with the name of your class.

This would cause it to be loaded on construction of the first construction of your first servlet that extends MyNew... and all instances of everything that extended
MyNew...  would use the same instance (hence static).

You could make tomcat load your servlet on startup.

Now this would make the same instance universally available from all instances of classes that inherit from MyNew...  Not JSPs etc.  For that consider maybe an accessor class made into a servlet.  Or perhaps making an EJB (www.jboss.org) out of it.

-Andy

I have a problem of persistance .. I have a package that is not a servlet nor a Server side component .............I want it instantiated along with the start up of tomcat and there after there should be only one instance of these objects in one instance of Tomcat !! Can someone help me to establish this please ? Thanks iin advance ,Eswar Subramanyam
Canal+ Techno
_______________________________
Do not judge, and you will never be mistaken.
 - Jean-Jacques Rousseau (1712-1778)
====================================================================
Olivier Tourdes
E-mail: [EMAIL PROTECTED]
Site: http://www.i-tipi.fr
====================================================================



Reply via email to