简体   繁体   English

Google App Engine(GAE)上的ThreadLocal

[英]ThreadLocal on Google App Engine (GAE)

I would like to make some request-wide data available in my app engine application. 我想在我的应用引擎应用程序中提供一些请求范围的数据。

Examples: 例子:

  • The URL for which the request was made. 发出请求的URL。
  • Authentication information. 验证信息。

I see that ThreadLocal is on GAE's JRE whitelist . 我看到ThreadLocal在GAE的JRE白名单上

Is ThreadLocal a good and safe way to make this information available? ThreadLocal是一种安全的方式来提供这些信息吗? Are there alternative / better / more accepted ways? 有替代/更好/更容易接受的方式吗?

Yes, it is an accepted practice to store these things in a ThreadLocal . 是的,将这些东西存储在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. 它更为可取,因为它至少可以测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM