Google App Engine (GAE) 上的 ThreadLocal

发布于 2024-09-08 11:38:09 字数 328 浏览 2 评论 0原文

我想在我的应用程序引擎应用程序中提供一些请求范围的数据。

示例:

  • 发出请求的 URL。
  • 认证信息。

我发现 ThreadLocal 位于 GAE 的 JRE 白名单。

ThreadLocal 是提供此信息的良好且安全的方法吗?有其他/更好/更容易接受的方法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷炫老祖宗 2024-09-15 11:38:09

是的,将这些东西存储在 ThreadLocal 中是一种公认​​的做法。然而,更好的方法是在需要的地方传递这些值(作为方法参数),而不是直接获取它们。它更可取,因为它至少更易于测试。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文