views:

60

answers:

1

I would like to make some request-wide data available in my app engine application.

Examples:

  • The URL for which the request was made.
  • Authentication information.

I see that ThreadLocal is on the whitelist: http://code.google.com/appengine/docs/java/jrewhitelist.html

Is ThreadLocal a good and safe way to make this information available? Are there alternative / better / more accepted ways?

+3  A: 

Yes, it is an accepted practice to store these things in a ThreadLocal. However, a more preferable approach is to pass these values around (as method arguments) wherever they are needed, instead of reaching for them. It's more preferable, because it's more testable at least.

Bozho