aspose file tools
The moose likes Servlets and the fly likes about servlet variable Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "about servlet variable" Watch "about servlet variable" New topic
Author

about servlet variable

haoxiang guo
Greenhorn

Joined: Mar 04, 2006
Posts: 3
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HolisticCounter extends HttpServlet {

static int classCount = 0; // shared by all instances
int count = 0; // separate for each servlet
static Hashtable instances = new Hashtable(); // also shared

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/plain");
PrintWriter out = res.getWriter();

count++;
out.println("Since loading, this servlet instance has been accessed " +
count + " times.");

// Keep track of the instance count by putting a reference to this
// instance in a hashtable. Duplicate entries are ignored.
// The size() method returns the number of unique instances stored.
instances.put(this, this);
out.println("There are currently " +
instances.size() + " instances.");

classCount++;
out.println("Across all instances, this servlet class has been " +
"accessed " + classCount + " times.");
}
}

can anyonn expalin the result
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56229
    
  13

Please read this.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12271
    
    1
At first glance I would say you got bit by one of the invoker servlet traps. Read the Invoker servlet FAQ here at the ranch
Bill
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: about servlet variable
 
Similar Threads
about threading in servlet.
Number of threads accessing a Servlet
Usage of Constant
Counter using Session Tracking !!
How to create a counter in my page?