Question

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 GAE's JRE whitelist.

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top