>From http://docstore.mik.ua/orelly/java-ent/servlet/ch03_03.htm
-------------------------------------
Just like applets, servlets can define init() and destroy() methods. A servlet's
init(ServletConfig) method is called by the server immediately after the server
constructs the servlet's instance. Depending on the server and its
configuration, this can be at any of these times:

    * When the server starts
    * When the servlet is first requested, just before the service() method is
invoked
    * At the request of the server administrator

In any case, init() is guaranteed to be called before the servlet handles its
first request. 

------------------
We use a dedicated servlet for every web app to make sure all prerequisites
are met. Since it's loaded first, we can find problems by looking at a single
piece of the log files just after the container messages announcing that
it's loading the app. 

We also avoid variable load times depending on the container's behavior
and setup.

Of course Mike does not need to do that if he has a only few inits related
to a single servlet.

Luc P.


Rob Lachlan <robertlach...@gmail.com> wrote ..
> The servlet interface includes the init method for this exact
> purpose.  In java, this would be used by subclassing one of the
> abstract servlet classes, and filling in the init method with whatever
> initialization you need.  Or by implementing the servlet interface
> directly.
> 
> From the javadoc, the init method "Initializes the servlet. The method
> is called once, automatically, by the servlet engine when it loads the
> servlet. It is guaranteed to finish before any service requests are
> accepted."  I find this approach more straightforward than having an
> entire separate servlet for initialization.
> 
> I was hoping that initialization of this kind would make it into the
> ring spec, but there wasn't much support.  See the thread below for
> more details:
> 
> http://groups.google.com/group/ring-clojure/browse_thread/thread/ec5a30b5bb4ec823#
> 
> Rob
> 
> 
> On Nov 27, 4:50 pm, Mike Meyer <mwm-keyword-googlegroups.
> 620...@mired.org> wrote:
> > My simple web app
> > (http://blog.mired.org/2010/11/x10-controller-in-clojure.html) has
> > some stuff that needs to happen just once (in this case, opening the
> > serial port). It's not clear how to get this to happen using ring. If
> > I do it inside my ring handler, then it gets run on every request, and
> > I have to check to make sure it's not run multiple times. If I run it
> > outside the handler, then it gets run when I do "lein uberwar", which
> > is simply wrong.
> >
> > When the deployment platform activates the war would seem to be the
> > right time to run this ("war load time"?). So maybe this is a question
> > that depends on the deployment platform, or war? However, a quick
> > google search didn't turn up anything that looked interesting.
> >
> > Anyone got suggestions on how to set up code to be run when Jetty (or
> > tomcat, or ...)?
> >
> >         thanks,
> >         <mike
> > --
> > Mike Meyer <m...@mired.org>          http://www.mired.org/consulting.html
> > Independent Network/Unix/Perforce consultant, email for more information.
> >
> > O< ascii ribbon campaign - stop html mail -www.asciiribbon.org
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first
> post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
Luc P.

================
The rabid Muppet

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to