users@glassfish.java.net

Re: Is it possible to put an object on the session in EJB3?

From: <glassfish_at_javadesktop.org>
Date: Fri, 09 Nov 2007 10:36:47 PST

Yea, theadlocal is usable. You need to make sure you synchronize up with the various lifecycle aspects within the container, because threads are reused. So, you just need to be careful to ensure that the value in the threadlocal is the one that you want and not from a previous invocation/transaction. Really depends on the nature of your data.

Also, note, you need to be careful if you're using, say, Remote Interfaces. I don't know if a WAR on the app server calling a local Remote bean uses one or two threads. So, if you expect the threadlocal set in the web tier to be there in the app tier, AND you happen to use a remote session bean call, you may well be on a different thread.

I don't know if that's true or not. I can see it working both ways.

WIth a local call, this isn't a problem.
[Message sent by forum member 'whartung' (whartung)]

http://forums.java.net/jive/thread.jspa?messageID=244805