[jboss-as7-dev] Issue with access to java:comp/UserTransaction from non EE threads

David M. Lloyd david.lloyd at redhat.com
Thu Jun 2 17:48:28 EDT 2011


On 06/02/2011 04:13 PM, Lincoln Baxter, III wrote:
> Hi Guys,
>
> I've written a little app (using Seam 3, RichFaces, a bunch of our
> projects, but namely Seam Persistence.) While working with Scott Marlow,
> we discovered that the reason for this failure:
> http://pastebin.com/KC7v90YK, is because the thread attempting to access
> the UserTransaction is outside of the EE threads: http://pastie.org/2010007
>
> This works well on JBoss AS6, but does not on AS7. Wondering if we
> should loosen up the access to the UserTransaction to anonymous/non-EE
> threads.

It's not a question of "loosening up".  The problem is that outside of 
EE, there is no "comp", it simply doesn't exist.  This is not a 
draconian policy created to torture users, it's just a reality of what 
is necessary to implement Java EE these days.

The "comp" namespace is so-named because it corresponds to a 
"component", such as an EJB or servlet (though due to historical quirks, 
"comp" is shared among all servlets in a WAR).  If you're not in a 
context associated with a component, then the AS cannot know which 
component's "comp" namespace to examine.

Java EE really has no provision to support creation of threads from a 
servlet or EJB, but nevertheless the real right answer is to get your 
thread associated with the component from which you want to look up 
UserTransaction, or get the data which needs a transaction back to an EE 
thread.

Note that in your example the thread is created by "twitter4j".  The 
only remotely spec-complaint options you currently have are to use 
JMS+MDB (overkill for sure) or JCA inflow (only somewhat overkill) with 
your own custom RA to talk to a custom MDB type.

In 7.1 we will have app client support, so when that time comes perhaps 
you could treat your handler as a client and perform direct invocations 
on your EJBs that way.

That's all the ideas I have right now...
-- 
- DML


More information about the jboss-as7-dev mailing list