Java EE – @ requestscoped CDI injection @ messagedriven bean

If I use JMS to inject request scoped CDI beans into the @ messagedriven EJB, as shown below, can I assume that any given foo instance can only be used by a single onmessage call at a time?

In other words, in the following example, can I safely use member variables in the foo object to store state across subroutines, similar to JSF @ requestscoped managed beans?

Please note that if the same foo object loops from one onmessage call sequence to the next, as long as each messagedrivenbean instance has its own foo instance, two concurrent requests can 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 = ...;
     }
 }

Solution

Wrt request scope / context, section 6.7 The CDI specification in Section 1 says that it is active for message - driven beans that implement messagelistener It will also be destroyed after the message is delivered, so you will provide a new instance for each delivered message In addition, section 6.7 Section 3 states that the application context is also active (as expected) Session and session scope are not active

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>