And*_*nea 2 java optimization jit java-8 javacompiler
如果我做
try(Lock lock = lockProvider.lock()) {
// some code that doesn't use variable lock
}
Run Code Online (Sandbox Code Playgroud)
编译器或JITer是否存在删除锁创建的风险,因为它在块中看到它未使用?
后来编辑:
一点背景.我来自.NET背景,在C#中,它允许执行以下操作:
using(Transaction tx = BeginTransaction())
{
// code that does things without touching the tx variable, such as SQL connections and stuff
}
Run Code Online (Sandbox Code Playgroud)
事实上它甚至可以缩短为
using(BeginTransaction())
{
// code that does things without touching the tx variable, such as SQL connections and stuff
}
Run Code Online (Sandbox Code Playgroud)
静态编译器和JIT编译器将保持BeginTransaction
调用,并且在运行时它将始终发生.
然而,在Java似乎是一个很大的问题和消极周围使用try-与资源用于其他的东西,是资源.
归档时间: |
|
查看次数: |
167 次 |
最近记录: |