Singleton Servlet

Discussions

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

  1. Singleton Servlet (3 messages)

    HI,

    I want to know what is a singleton servlet and how to create it?

    Any instructions will help.

    Thanks
    Meeti

    Threaded Messages (3)

  2. Singleton Servlet[ Go to top ]

    maybe you need a "startup servlet" which runs 1 time when the application server starts.
  3. Singleton Servlet[ Go to top ]

    Singelton servlet is similar to having a single instance of any POJO in the JVM.
    To achieve a single instance of servlet being loaded in the container, you can go by implementing the singleThreadModel interface. This being a marker interface will tell your container that a single instance is to be maintained.

    But beware, this interface is deprecated from servlets 2.3 onwards and also by implementing this interface you can face performance problems as the container will que all your request to this servlet instance.It actually makes the service() synchronized and ensures no other thread gets the service() when some current thread is executing.

    Cheers
    VIJAY
  4. Hi,

    According to my understanding by default Servlet is singleton. It will create multiple threads to process multiple requests, but it doesn't create multiple instances of a servlet.

    Thanks,
    Mallik