What is single thread model and multi thread model in servlet?

Container create one or more servlet instance depending on which servlet model you are using.
There are two servlet model:
  • Single Thread Model
  • Multi Thread Model
Single Thread Model:
To follow single Thread model your servlet class has to implement interface called SingleThreadModel.It is a marker interface.
In the case of single Thread Model servlet instance will be created for every incoming request that is multiple servlet instance will be created for Single Thread Model.
It is not recommendable to use SingleThreadModel because multiple instance of a servlet will not be reused. So no use of maintaining many instance for long time. This is may be cause the problem like performance & memory wastage.

Multi Thread Model
By default container follows Multi Thread Model.
Only one servlet instance will be created and the same instance will be used to provide the service to every incoming service.
It is always recommended. 

1 comment :

  1. Nice Article ... Please explain it in details if possible. And plz give example of how to implement single thread model and multi thread model.

    ReplyDelete