It depends on the JAX-RS resource area and the idle service of the service.
Typically, each instance of a JAX-RS resource is created each time it is requested.
JSR339 3.1.1 Life Cycle and Environment
By default, a new instance of the resource class is created for each request for this resource. First, the constructor (see Section 3.1.2), then any requested dependencies are entered (see Section 3.2), then the corresponding method (see section 3.3), and finally, the object becomes available for garbage collection.
For the next HTTP request
GET /pizza HTTP/1.1
A new instance of PizzaResource and an available instance of PizzaService is inserted into it.
Now the answer you are looking for depends on statelessness and the PizzaService life cycle that the container can support.
Hopefully I can't find the spec now, but even if PizzaService is @Stateless , the containers will not share the instance at the same time for different sessions.
I would put a lifecycle listen method to reset the service.
@Path("/pizza") public class PizzaResource { @PostConstruct private void resetPizzaService() {
Where reset() will do
public void reset() { peperoni = false; cheese = false; bacon = false; }
Update
I found a nice thread for @Service , which seems to be part of the Spring framework. How does singlet bean serve for simultaneous request?
source share