On Sun, 09 Jan 2005 17:05:04 -0500, Frank W. Zammetti wrote:
> The only thing that's like a global in Java is a static variable (static
> final usually, but in this case just static).

Another good trick in a web app is to use the ThreadLocal class to
simulate globals that are thread specific. AFAIK, all servlet
containers use one thread to process a request (unless you are doing
some funky stuff with threading in your application).

What that means is that you can extend ThreadLocal and use that class
as you would a static variable, but its data is only shared by code
executing on one thread.

Where I work, we use a filter to call ThreadUser.setUser() with a User
object - so anywhere in the application, we can reference
ThreadUser.getUser() (as if it were static), and always get the user
that the thread is serving.

Larry

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to