Page 1 of 1

About Question enthuware.jwpv6.2.580 :

Posted: Thu Jan 10, 2013 2:04 pm
by gurpreet_asrgndu
the doubt is related to what is written in the specs. acc to the specs

Dispatching from a synchronous servlet to an asynchronous servlet would be illegal. However the decision of throwing an IllegalStateException is differed to the point when the application calls startAsync. This would allow a servlet to either function as a synchronous or an asynchronous servlet."

Therefore, in the given situation where the target servlet processes each request asynchronously, an IllegalStateException will be thrown.

if dispatching from synchronous servlets to asynchronous servlet will throw IllegalStateException when startAsync() is called then why the spec says "THIS WOULD ALLOW A SERVLET TO EITHER FUNCITON AS A SYNCHRONOUS OR AN ASYNCHRONOUS SERVLET". i think this is logically incorrect.

Re: About Question enthuware.jwpv6.2.580 :

Posted: Sun Jan 13, 2013 4:16 pm
by admin
If the target servlet is able to process request synchronously and doesn't call startAsync, then the exception will not be thrown. So, I think it is ok.

HTH,
Paul.

Re: About Question enthuware.jwpv6.2.580 :

Posted: Thu Jul 11, 2013 11:51 pm
by JoeAllen
I misinterpreted one of the correct answers,"A servlet can work in both synchronous and asynchronous mode.", as, "a servlet can work in both modes at the same time", but in fact it can only work in one mode at a time, which is just like what the spec says, "THIS WOULD ALLOW A SERVLET TO EITHER FUNCITON AS A SYNCHRONOUS OR AN ASYNCHRONOUS SERVLET", not "FUNCITON BOTH AS A SYNCHRONOUS AND AN ASYNCHRONOUS SERVLET".
For example, one being capable of playing chess and football doesn't mean he can play both at the same time. He has to play either chess, or football, not both at the same time.

Re: About Question enthuware.jwpv6.2.580 :

Posted: Fri Jul 12, 2013 7:45 am
by admin
Not sure what you mean by "at the same time". It can process one request asynchronously and another one synchronously. Obviously, it can't process the same request synchronously as well as asynchronously. So I am not sure what is the confusion.
-Paul.

Re: About Question enthuware.jwpv6.2.580 :

Posted: Sat Apr 09, 2016 9:58 pm
by himaiMinh
Is this an example of a servlet that can be in both asyn. and sync mode:

Code: Select all

@WebServlet(asyncSupported="true"....)
public class MyServlet extends HttpServlet{
 public void doGet (HttpServletRequest request....){
            //do nothing
 }
}
Even though the servlet supports async processing, but the doGet method does not have
request.startAsync(). So, this servlet is synchronous ?

Re: About Question enthuware.jwpv6.2.580 :

Posted: Sun Apr 10, 2016 11:21 pm
by admin
Yes, that is correct. This servlet basically processes the request in synchronously.