• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

service method...

 
Nikhil Jain
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had the following questions in one of the mock, I don't remember the exact question, but the question overided the service method like
public synchronized void service(request, respnse) {
super.service(req, res);
}

are the implications same as overriding doGet & doPost()
 
srilatha kareddy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

get this picture in mind

HttpServlet ....has thses methods
1.public void service(ServletRequest req,ServletResponse res)throws ServletException,java.io.IOException
//Dispatches client requests to the protected service method
2.protected void service(HttpServletRequest req,HttpServletResponse resp)throws ServletException,java.io.IOException
//dispatches them to the doXXX methods

your servlet will extend HttpServlet ...so if you override service method it will not dispatch properly to doXXX methods....but if you override any of doXXX methods there will not be any problem
 
Nikhil Jain
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No I guess this would still call the doXXX methods as It has super.service(httpServReq, httpServRes)...

secondly what if there as 2 doxxx methods, one that synchronizes & other that does not.. .Will this mean that there would be only single thread for doGet & multiple threads for doPost assuming that these are the only 2 methods coded for the Servlet...
 
srilatha kareddy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
yep i went on writing about overriding and completely missed super.service

you already got answer for doXXX synchronization

if doGet is synchronized ..then at any given point only 1 thread can be accessing doGet
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic