Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-3471

Scope of JMSContextProducer should be either @Request or @Tx not default

XMLWordPrintable

      From this email thread.

      Note that if you @Inject JMSProducer into a @ApplicationScoped bean then that's the scoping used, although it's not correct as the scope should be either @Request or @TransactionScoped

      To: users@jms-spec.java.net
      Subject: [jms-spec users] Re: Confusion about JMSProducer methods and CDI

      On 05/06/2014 19:29, Elias Ross wrote:
      >
      > The other question I had was the scoping for CDI. For example:
      >
      > @ApplicationScoped
      > public class MyClient

      { > @Inject JMSContext context; > }

      >
      > public class MyServlet extends HttpServlet

      { > @Inject MyClient client; > }

      >
      > Then JMSContext ends up being potentially shared between multiple
      > threads. I would expect the scoping of JMSContext to be request, not
      > @Dependent here.
      >

      Why do you say that the "JMSContext ends up being potentially shared between multiple threads"?

      The scope of the injected JMSContext is defined in the JMS 2.0 spec, section 12.4.4. "Scope of injected JMSContext
      objects". Essentially, if there's a transaction in progress then the injected JMSContext will have transaction scope,
      otherwise it will have request scope.

      It looks like you're in a servlet here, and you haven't started a transaction, so the injected JMSContext must have
      request scope.

      The scope of the injected JMSContext is defined in the JMS 2.0 spec, section 12.4.4. "Scope of injected JMSContext objects". Essentially, if there's a transaction in progress then the injected JMSContext will have transaction scope, otherwise it will have request scope.

      It looks like you're in a servlet here, and you haven't started a transaction, so the injected JMSContext must have request scope.

              jmesnil1@redhat.com Jeff Mesnil
              genman_jira Elias Ross (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: