sorry - when I said "instance" in this, I don't mean that at all - I really
mean I want variables that are independent and unique each time you call the
same instance. ie I guess I want:

public class blah extends HttpServlet
{
        int x;

        public void doGet (...)
        {
                if (some test)
                {
                        x = 1;
                }
                else
                {
                        x = 2;
                }
                evaluate ();
        }

        private void evaluate ()
        {
                out.println (x);
        }
}

such that you can safely call that lots of times, simultaneously, and the
correct value of x will always be displayed.

-----Original Message-----
From: Ben Coppin [mailto:[EMAIL PROTECTED]]
Sent: Monday, August 16, 1999 9:50 AM
To: [EMAIL PROTECTED]
Subject: instance variables in servlets


Hi,

I apologize in advance if this seems like a dumb question:

I've recently written my first servlet, and I guess due to a lack of
understanding on my part I gave the class a few member variables  which
needed to be unique to each instance of the class.

Am I right in thinking that class member variables really just aren't a good
idea in servlets unless you want to share information between instances?

What I'd like to know is: is there a sensible way of having variables that
act like normal java class member variables (ie they're avaialble to all the
classes non-static functions) but which are safe to use without interfering
with other instances? Do I just need to make my class extend
SingleThreadModel?

Thanks,

Ben

___________________________________________________________________________
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

___________________________________________________________________________
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