About Question enthuware.jwpv6.2.580 :

Moderator: admin

Post Reply
gurpreet_asrgndu
Posts: 55
Joined: Thu Jan 03, 2013 7:51 am
Contact:

About Question enthuware.jwpv6.2.580 :

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.580 :

Post 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.
If you like our products and services, please help us by posting your review here.

JoeAllen
Posts: 13
Joined: Thu Jul 11, 2013 11:22 pm
Contact:

Re: About Question enthuware.jwpv6.2.580 :

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.580 :

Post 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.
If you like our products and services, please help us by posting your review here.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.580 :

Post 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 ?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.580 :

Post by admin »

Yes, that is correct. This servlet basically processes the request in synchronously.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests