You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Ja...@cardsetc.com on 2000/04/13 10:36:23 UTC

Solutions to initialising static data

Folks,

This ones a general servlet programming pattern question.

Let's say I have a class that has some static methods and static data.
Various servlets are going to access this class at various points, before
they can do that, the class needs to be initialised, preferably by an
outside entity (ie. not by including a static initialiser that searches the
CLASSPATH for its configuration file).

I could do this by writing a servlet that's loaded at startup, which does
the necessary initialisation in its init() method.  Any configuration data
required by the static class can be obtained via the servlet's
initialisation parameters.

However, something irks me about having to write a servlet just for this
purpose.  The servlet has no other reason for being - and might potentially
receive calls from the client.  I could piggy back the responsibility for
initialisation of this class to, say, my login servlet - but that seems to
be adding in unnecessarily coupled logic.

Does anyone have any other suggestion, or comments on the relative merits
of these solutions.

     1. search for config file on class path in static initialiser
     2. special initialisation servlet which does nothing else and makes
itself unavailable
     3. adding functionality to some other servlet that the first user
connecting to the system MUST go via.

Regards,
James W.

--------------------------------------------------------------------------
Cards etc will be on stand 1161 at CardTech SecurTech in Miami
from 2nd May to 4th May. Look forward to seeing you there!
--------------------------------------------------------------------------
This e-mail is from Cards Etc Pty Ltd (ACN: 069 533 302). It may contain
privileged and confidential information. It is intended for the named
recipient(s) only. If you are not an intended recipient, please notify us
immediately by reply e-mail or by phone on +61 2 9212 7773 & delete this
e-mail from your system.
--------------------------------------------------------------------------