If I have a request scoped CDI bean injected into a @MessageDriven EJB using JMS, as below, can I assume that any given Foo instance will only be used by a single onMessage invocation at a time?
In other words, in the below example, can I safely use member variables in the Foo object to store state across subroutines, analogously to a JSF @RequestScoped managed bean?
Note that it's ok if the same Foo object gets recycled sequentially from one onMessage call to the next, as long as each MessageDrivenBean instance has its own Foo instance such that two requests processing concurrently would be isolated.
@MessageDriven
public class MessageDrivenBean implements MessageListener {
@Inject
private Foo foo;
public void onMessage(Message m) {
foo.doSomething();
}
}
@Named
@RequestScoped
public class Foo {
private String property;
public void doSomething() {
property = ...;
}
}