Discussions

Web tier: servlets, JSP, Web frameworks: Singleton Servlet ?

  1. Singleton Servlet ? (3 messages)

    i want to have only one instance of servlet.
    how to make singleton Servlet ?

    Threaded Messages (3)

  2. Singleton Servlet ?[ Go to top ]

    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?
  3. Singleton Servlet ?[ Go to top ]

    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.
  4. Singleton Servlet ?[ Go to top ]

    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