> -----Original Message-----
> From: Ashok MAdhavan [mailto:[EMAIL PROTECTED]]
> Sent: 20 July 1999 12:43
> Subject: Inter servlet comm and Session
>
>
> Hi guys,
>
> I would like to access an object across servlets in a session. one way
> would be store the object along with your session and we can retrieve
> it.But the object is slightly big and there is one object per session
> and there are many concurrent users. so the session object might become
> large.this might become a load on the server.
> is there any other way of accessing of object across servlets in a
> session.

Hi,
If you only need a single object shared across lots of sessions then I
suggest the use of the Singleton design pattern so that only one instance of
the object exists (although you might have many references to it).

Here is a simple example:

public class MySingleton {
        private MySingleton singleInstance = new MySingleton();

        /* Note that the constructor is 'private' so that
         * it cannot be constructed by another class
         */
        private MySingleton() {
                // constructor stuff
        }

        /* This is where other classes get a reference
         * to the single instance
         */
        public MySingleton getInstance() {
                return singleInstance;
        }

        //other methods
}

(Don't forget that because the single instance of this class could be used
by lots of other objects, you need to be careful about concurrency.)

Hope this is helpful, (maybe I misunderstood you question ?).

Channing

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to