i want to have only one instance of servlet.
how to make singleton Servlet ?
-
Singleton Servlet ? (3 messages)
- Posted by: Shahaji Kadam
- Posted on: May 02 2003 03:06 EDT
Threaded Messages (3)
- Singleton Servlet ? by Anil Saldhana on May 02 2003 11:16 EDT
- Singleton Servlet ? by Web Master on May 02 2003 16:01 EDT
- Singleton Servlet ? by SAF . on May 02 2003 16:46 EDT
-
Singleton Servlet ?[ Go to top ]
- Posted by: Anil Saldhana
- Posted on: May 02 2003 11:16 EDT
- in response to Shahaji Kadam
I am not sure whether you can do that. Why don't you move the biz code from the servlet into a java class/bean and make that a singleton? -
Singleton Servlet ?[ Go to top ]
- Posted by: Web Master
- Posted on: May 02 2003 16:01 EDT
- in response to Shahaji Kadam
Your servlet is already a singleton since the container in which it runs only loads one instance. The container spawns a thread to service each request.
Unless your servlet implements SingleThreadModel, your servlet will only have one instance loaded. -
Singleton Servlet ?[ Go to top ]
- Posted by: SAF .
- Posted on: May 02 2003 16:46 EDT
- in response to Shahaji Kadam
It sounds like you are attempting to control concurrent access to this servlet, which would mean that you can declare the servlet to implement SingleThreadModel, but I would not recommend that since it would degrade performance.
Provide more information as to what you are trying to accomplish. Here's a tip when using servlets: Avoid variables at the servlet instance level, and declare all of your variable as automatic (inside the doGet() doPost(), etc methods), and by doing so you are always safe when multiple threads are serviced by the single servlet instance.
SAF