This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet models  RSS feed

 
Skanda Raman
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
He was probably fishing for Model 1 and Model 2. See this article for more information.
 
Nick White Ro
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!