Hi, I have a need to write to a file from multiple servlets, possibly all
sending requests at the same time. So, I have an object which is created in
the init() routine of one of my servlets, as follows:

                pieLog myLog = new pieLog();
                getServletContext().setAttribute("myPieLog", myLog);

Now, other servlets access this object like this:

        pieLog myLog = (pieLog) getServletContext().getAttribute("myPieLog");

pieLog is just a straightforward class defined like this:

public class pieLog {
    ....define vars here

    public pieLog() {
                  ...initialize stuff, open up the file for writing
    }

    public void sychronized dostuff(parameters) {
         ...do stuff to the file
     }
}

  This is all working, pretty much. But I am confused about how to ensure
that the object is initialized before other servlets attempt to use it? Can
I tell the servlet which creates the object to be initialized on the
servlet engine startup? I have been looking over the archives on this
mailing list, and I am also concerned about comments that servlets may be
created multiple times, or run in different contexts, at the discretion of
the servlet engine. Does this mean I need a different approach? Thanks so
much!

   -Bryan


--==================================--
  Bryan Roach <[EMAIL PROTECTED]>
  National Center for Supercomputing Applications
  Research Programmer -- Communications Group
  217.265.0462

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to