Maybe I missing something in your question, or could you also use a
Singleton?
This is available to not only servlets... but maybe what you are looking
for.


public class MySingletonObject {

        // private constructor
        private MySingletonObject () {
        }

        // static getInstance Method
        public static MySingletonObject getInstance() {
                return me;
        }

        // static var, only one instance of me
        private static MySingletonObject me = new MySingletonObject ();
}

Cheers, Rob.

-----Original Message-----
From: Guillaume Barreau [mailto:[EMAIL PROTECTED]]
Sent: 19 December 2000 12:13
To: [EMAIL PROTECTED]
Subject: creation of application wide objects


Dear Tomcat users,

What is the best way to create some objects which are going to be available
application-wide to a bunch of servlets from the same web-app? Or in other
words, is there an equivalent of an init() method but for the application as
a
whole?

At the moment, I am having to clutter the init() method of all my servlets
with
code to check if the object has been created and create it if it hasn't. I
have
to do that because I am not sure which servlet will be invoked first.

Am I missing something? Is there any way to do that in the xml descriptor
file?

Thanks for your help,

Guillaume Barreau

Reply via email to