• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet models

 
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was asked the following question in an interview

Let me know two models available in servlet.

If i am right, one would me single thread model.

Can you please let me know if this right and what is the second one.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Model" can mean any number of things; did you ask the interviewer for clarification?
 
Skanda Raman
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interviewer asked me in context of using the servlet models in my project.

Initially i could not tell the answer, later he said there are two servlet models and asked me to list those.

As i said single thread model, he said thats fine what about other.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
He was probably fishing for Model 1 and Model 2. See this article for more information.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
He was refering to the 2 servlet thread models:

1. Multi threaded model: the container holds a single instance of a servlet, but executes the service() method in separate threads, one for every request.
2. Single threaded model: the container still holds a single instance of a servlet, and the servlet implements SingleThreadModel; virtually, this means that the service() method is synchronized, so if you have multiple requests, they will have to stay in line. Using this model is generally a bad practice, as a result the interface is now deprecated.

My guess is you used instance variables in your servlets. If you use them in the service() method (and the servlet is not single threaded), the operations are not thread safe (remember, you have only one instance on the container, but multiple requests).
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nick White Ii wrote:He was refering to the 2 servlet thread models:

It's hard to guess from the information provided, but I don't think so. I think he was looking for the structural models as posted above.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic