When multiple requests are sent by multiple clients at the same time, how many servlet instances are created
Can we create multiple instances of the same servlet without implementing SingleThreadModel interface
can anyone help me on this issue
Printable View
When multiple requests are sent by multiple clients at the same time, how many servlet instances are created
Can we create multiple instances of the same servlet without implementing SingleThreadModel interface
can anyone help me on this issue
Hi,
only one servlet instace is created by servlet container.We cannot create a servlet instance explicitly. And for single instance multiple threads are created. If you implement SingleThreadModel interface only one thread will access the servlet instance otherwise multiple threads will access it simulaneously.
Still if you have any issues please let me know.
Thanks
--suresh--
[QUOTE=srikanthm2;24967]When multiple requests are sent by multiple clients at the same time, how many servlet instances are created
Can we create multiple instances of the same servlet without implementing SingleThreadModel interface
can anyone help me on this issue[/QUOTE]
As far as number of instances of servlet is concerned it depends on the servlet container implementation i.e container vendors how they implement the servlet specification.
They may create multiple instances and use servlet pooling.
If the servlet container is made to create only one servlet instance by default then also you can create more than one. In the web.xml file declare the servlet taggings multiple times but the name should be different or it will give DTD error. to check this write a default constructor in the class make load on startup tag +ve and start tomcat6 u will c the constructor is called twice. Thus we an have as many servlets as we want.
The instances are called using the servlet name's value. In this case also only the first declaration will be used and its initial configs to serve the requests. Not he second one. only thing is that we can get multiple instances explicitly but will be useless as the call to the instance is done implicitly by container and it will use the one name value only. To support this we can say that for the same servlet we can have two contradictory configuartions so thats worthless.
Hope it helps