Most likely, your servlet runner uses a new servlet classloader for each
defined servlet. Even though they use the same class file, its the
combination of the class file + classloader that make up a unique Class in
the JVM. As a test, try putting your servlet class file in a directory that
is in the system classpath. If you want to share information this way
between servlets, you could have a seperate class that is in the system
classpath that is referenced (loaded) in your init().

I am sure that there are others on this list who can give you better ways to
share info between servlets.

John Zerbe - Mellon Bank
IM&R - Middleware Team
Phone:  412-234-1048   E-Mail:[EMAIL PROTECTED]



> -----Original Message-----
> From: Dr. Dragomir D. Dimitrijevic [SMTP:[EMAIL PROTECTED]]
> Sent: Wednesday, October 06, 1999 12:56 PM
> To:   [EMAIL PROTECTED]
> Subject:      Re: Sharing static variables between servlets.
>
> I have the same problem with Apache/Jserv. All servlets use
> a pool of global static variables and methods defined in
> a class Globals. Each servlet kicks-off its own JVM so
> I end-up using more memory. Luckily,
> variables are read-only.
>
> So, I would like to know the solution too.
>
> DD
>
> ----------
> From:   David Finch[SMTP:[EMAIL PROTECTED]]
> Sent:   Wednesday, October 06, 1999 06:11 PM
> To:     [EMAIL PROTECTED]
> Subject:        Sharing static variables between servlets.
>
> Hi all,
>    I'm having trouble with what should be a simple feature: sharing a
> static variable between two instances of the same servlet class.
>
> Take the following example to demonstrate the problem...
>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class MyCounter extends HttpServlet
> {
>  private int counter = 0;
>  static int globalCounter = 0;
>
>  public void doGet(HttpServletRequest req, HttpServletResponse res) throws
> ServletException, IOException
>  {
>   res.setContentType("text/html");
>   PrintWriter out = res.getWriter();
>   out.println("<HTML><BODY>");
>   out.println("Count ="+(counter++)+"<br>Global count =
> "+(globalCounter++));
>   out.println("</BODY></HTML>");
>  }
> }
>
> >From here I configured the Servlet Attibutes twice with distinct names,
> but both pointing to the same class. I then configured two virtual paths
> for each of these servlets. However, they then run independently of each
> other: i.e. as though each servlet were running in a seperate JVM? The
> static counter behaves just as though it were not static. Is this the
> correct way to get two servlets to run from the same class?
>
> FYI: I'm using Netscape Enterprise Server 4 SP1.
>
> Thanks in advance.
>
> David Finch.
> **********************************************************************
> This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they
> are addressed. If you have received this email in error please notify
> the system manager.
>
> This footnote also confirms that this email message has been swept by
> MIMEsweeper for the presence of computer viruses.
>
> Premiere Technologies (UK)
> **********************************************************************
>
> __________________________________________________________________________
> _
> 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

___________________________________________________________________________
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