"It is not running under its own JVM, but each webapp *does* run under its
own classloader. Static variables are global only within the scope of a
particular classloader, so each webapp that uses your class gets its own if
the class was loaded from WEB-INF/classes or WEB-INF/lib. "
-Craig McClanahan, 09/15/2000

If the above is true, then why do I get the SAME VALUE for getTest() when
run under different contexts on?  The static test is already initialized on
the second context that I invoke it under?  and this issues only occurs
under linux, it works fine under win32.

Give the code below:
public class StaticTest extends HttpServlet
{
        private static int test = 0;
        public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException
        {
                response.getWriter().println(getTest());
        }

        public static int getTest()
        {
                if (test == 0)
                        test = new Random().nextInt();
                return test;
        }
}



Thanks Zach


Reply via email to