tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Cook" <jimc...@iname.com>
Subject Re: servlet question !!
Date Thu, 08 Jun 2000 13:00:04 GMT
Manpreet,

Consider that there is one instance of this class living in the servlet
engine. The first request to this servlet will cause the servlet to be
initialized. Count will equal 0. The output will be count++, or 1.
Subsequent requests (by the same client or others) will continue to
increment count. This will return 2, 3, 4, etc.

BTW, the servlet is reentrant, meaning that one or more of these clients can
be in the servlet concurrently. It is possible that two clients hitting your
code could return the same output value.

jim

----- Original Message -----
From: Manpreet <manpreetnagpal@yahoo.com>
To: <tomcat-user@jakarta.apache.org>
Sent: Thursday, January 06, 2000 3:47 PM
Subject: servlet question !!


HI all,

I have a small servlet code like this:

import java.io.*;
import javax.servlet.*;
import java.servlet.http/*;

public class Test extends HttpServlet {
        int count=0;
        public void doGet(HttpServletRequest req , HttpServletResponse res)
throws         IOException , ServletException {
            PrintWriter out=res.getWriter();
            out.write(count++);
        }
}

Is it possible that each request to this servlet gets the initial value of
count i.e. 0

thanks in advance ,
Manpreet Singh.




Mime
View raw message