tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <>
Subject RE: Different URLs for different instances of the same servlet
Date Fri, 29 Sep 2000 19:10:44 GMT
You will get different instances in the following case:

make a URL mapping for a servlet I am including in this email

1. go to that servlet based on the URL mapping

2. go so the servlet based on the default /servlet/ way using the same

Here is the code to test:

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 {
		PrintWriter out = res.getWriter();
		int local_count;
		instances.put(this, this);
		int instance_size;
		int local_classCount;
		synchronized(this) {
			local_count = ++count;			
			instance_size = instances.size();
			local_classCount = ++classCount;
		out.println("Since loading, this servlet has been accessed "
+ local_count + " times.");
		out.println("There are currently " + instance_size + "
		out.println("Across all instances, this servlet has been
accessed " + local_classCount + " times.");



Hope that helps,


-----Original Message-----
From: Shannon Bradshaw []
Sent: Friday, September 29, 2000 1:52 PM
Subject: Different URLs for different instances of the same servlet

I'm building an application for which I need to treat servlets as both
servlets called from a Web browser and RMI-accessible objects to be called
from other components in a distributed system.  I'd like to write a servlet
class for which I can run instances that persist for the duration of a user
session and can be referenced with urls distinguished from one another using
a session identifier.  The HttpSession API won't work for me as I need the
objects to be more than simply attribute holders, and want each "Session
Servlet" to run in parallel with the others.

I have been experimenting with Tomcat, but have found not workable solution.
Does anyone know if there is a way of creating multiple instances of a
servlet that are referenced using distinct urls in Tomcat?  Is there some
other container that permits this?


View raw message