Given that a developer implemented a web service using Stateless Session EJB:
If a web service client invokes increment web service method twice consecutively, what must be the returned value after the second invocation ? (Choose one)
A.
0
B.
1
C.
2
D.
3
E.
Undefined
Response is B because this Web Service is a EJB and the class is instantiated each time a operation is called being the count zeored.
If the Web Service is based in servlets, then the class is only instantiated once and the subsequent calls would increment the count.
Thanks Macro, I agree: for servlet based web service, the class would be instantiated once when the servlet is invoked 1st time. for stateless session EJB based web service, the class would be instantiated upon invocation each time.
I also believe the correct answer is B , the value will be 1 each time
I think the correct answer is E
I think, The answer is E be cause we dont know any request will be traited firsly
Advantages of Statelessness
Following are the benefits of statelessness in RESTful web services
Web services can treat each method request independently.
Web services need not to maintain client’s previous interactions. It simplifies application design.
As HTTP is itself a statelessness protocol, RESTful Web services work seamlessly with HTTP protocol.
i already implement this web service every time execute web service the counter increased by One after two hits the returned value was 2 so answer is C
A stateless server is a server that treats each request as an independent transaction that is unrelated to any previous request.
I disagree, Mohamed
Un stateless no mantiene la conversación con el cliente quien lo ejecuta.
Si el service “Counter” es invocado el container verifica si hay una instancia activa en el pool, si existe una instancia activa esta misma atiende el cliente, si no existe el contenedor procede a crear otra instancia para soporta la solicitud.
para este punto puede pasar 2 escenarios:
1)si existe un “Counter” activo en el pool significa que algún cliente ya había invocado este servicio ya sea por RMI o por WS, para este caso la variable counter != 0
2)Si en la segunda invocación hay otro cliente (thread) que también hace la solicitud simultáneamente el valor de la variable counter puede ser (counter == 0 or counter != 0)
E is correct
correct is E, since it is stateless EJB, the EJB pool may have several instances of this EJB, so we have no idea which instance it will use for the 2nd call, then the returned value is undefined.
E)