This was answered (again, it's a popular question) yesterday.
Whether a static is global or not depends on where the class is loaded
from. If it's loaded from /WEB-INF/classes or /WEB-INF/lib, the static is
local to your web app. If the class is loaded from Tomcat's "lib"
directory, or from the CLASSPATH, it is global to all web apps.
Craig
On Thu, 23 Aug 2001, Zach Hollandsworth wrote:
> Date: Thu, 23 Aug 2001 16:27:14 -0500
> From: Zach Hollandsworth <[EMAIL PROTECTED]>
> Reply-To: [EMAIL PROTECTED], [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> Subject: static variables in multiple contexts PLEASE HELP
>
> I have asked this question a couple of times in here with no replies. I
> have two separate contexts with the same class. The class has a static
> variable and I would like to have different static variables across
> contexts. the source to an example class is as follows:
>
> 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;
> }
> }
>
>
> It appears to work as I expect with a different number for each context it
> is placed in on a windows platform, but on linux, the numbers returned are
> the same and the static is set once!
>
>
> should it be?
>
>
> thanks
> Zach
>
>
>