首页 \ 问答 \ ThreadLocal变量的性能(Performance of ThreadLocal variable)

ThreadLocal变量的性能(Performance of ThreadLocal variable)

ThreadLocal变量读取多少比常规字段慢?

更具体地说,简单的对象创建比访问ThreadLocal变量更快或更慢?

我假设它足够快,所以每次创建ThreadLocal<MessageDigest>实例要快得多,因此ThreadLocal<MessageDigest>实例要快得多。 但是,这也适用于byte [10]或byte [1000]吗?

编辑:问题是当调用ThreadLocal的时候会发生什么事情? 如果这只是一个领域,像任何其他的,那么答案就是“总是最快的”,对吧?


How much is read from ThreadLocal variable slower than from regular field?

More concretely is simple object creation faster or slower than access to ThreadLocal variable?

I assume that it is fast enough so that having ThreadLocal<MessageDigest> instance is much faster then creating instance of MessageDigest every time. But does that also apply for byte[10] or byte[1000] for example?

Edit: Question is what is really going on when calling ThreadLocal's get? If that is just a field, like any other, then answer would be "it's always fastest", right?


原文:https://stackoverflow.com/questions/609826
更新时间:2022-12-01 07:12

最满意答案

您不能内嵌JS对象,但您可以JSON.stringify之前:

<script type="text/javascript">
  var data = !{JSON.stringify(data)};
</script>

You can't inline a JS object like that, but you can JSON.stringify it before:

<script type="text/javascript">
  var data = !{JSON.stringify(data)};
</script>

相关问答

更多
  • 渲染完成后,只会将呈现的HTML发送给客户端。 因此,任何变量都将不再可用。 您可以做什么,而不是将输入元素中的对象编写为渲染JavaScript的对象: script(type='text/javascript'). var local_data =!{JSON.stringify(data)} 编辑:显然,玉第一个圆括号后需要一个点。 When rendering is done, only the rendered HTML is send to the client. Therefore ...
  • 您不能内嵌JS对象,但您可以JSON.stringify之前: You can't inline a JS object like that, but you can JSON.stringify it before: