TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

JEP 506: Scoped Values final for Java 25

34 点作者 ludovicianul28 天前

4 条评论

Pet_Ant27 天前
So it sort of looks like a DSL for a variant of ThreadLocal that gives you an idea of the lifeline of variable instead of just being global. Apparently with virtual threads they are expecting an increase in the number of running (virtual) threads several orders of magnitude larger than what was previously seen and that with ThreadLocals would just be too much.<p>So the have added this:<p>&gt; ScopedVaule.where(CONTEXT, context).run(() -&gt; Application.handle(request, response));<p>Which stores the object referenced by `context` to the ScopedValue container `CONTEXT` ^ for the duration of the thread running `Application.handle(request,response)`.<p>Not really sexy, but I understand how you might really benefit if you are processing lots of data, but for most enterprise CRUD apps this seems inapplicable.<p>^ I think this a &quot;monad&quot;? I&#x27;m not a functional programmer.
评论 #43700019 未加载
bhawks27 天前
Implicit parameter smuggling by any mechanism is just too much magic in my experience. Golang&#x27;s context.Context solves the same problem, but explicitly in a way that has been widely adopted through their language ecosystem.<p>That said - in Java I do think it would be near impossible for the ecosystem to adopt a similar mechanic, so from a practical standpoint this may be the only way to reliably propagate context.
评论 #43704692 未加载
djenndhxhd28 天前
Tramp parameters are a common occurrence, if not avoided with care.<p>I see value in this proposal
skerit28 天前
Interesting proposal, I can see myself using this.