Request context


EJB programming & troubleshooting: Request context

  1. Request context (3 messages)

    Hello I would like to put objects in an EJB transaction context, using something like ServletRequest.setAttribute/getAttribute, to access them later (but always in the same transaction). In my case, it's a single stateless session bean method that creates a transaction, calls methods on local entity beans, and the entity beans have to share this object pool for the duration of the transaction. Is there a way to do this? I am aware of ThreadLocal storage, but what if the application server decides to serve a call to an EJB method with one thread an other call with an other thread? Does the J2EE spec prohibit this behaviour? Thanks, Martin

    Threaded Messages (3)

  2. Re: Request context[ Go to top ]

    With container managed transaction, you cannot do it but if you can use UserTransaction to demarcate your own transaction boundaries and you can TransactionManager.getTransaction() to get the transaction object associated with current thread, here you can enlist your resource and retrieve later. try and tell me if it works.
  3. Re: Request context[ Go to top ]

    Enlisting XAResources seems quite elegant, but I don't see how I could retrieve the XAResource. My first idea was to have a static map with Transaction objects as keys. But this will never scale... Could any spec guru tell me if the ThreadLocal is a safe option?
  4. TransactionLocal[ Go to top ]

    This is what I want: Does anybody know if it is portable (to websphere 6 in particular)? Thanks, Martin