If you have two operations that require synchronization separated by a small block of thread-safe code, you are generally better just using a single synchronized block.
要是您想用一小块线程安全代码把要求同步的两个操作隔开,那么只使用一个同步块一般会更好些。
Note that this code is fully thread safe.
注意这样的代码是完全线程安全的。
On the surface it looks as though lock elision allows us to write thread safe code without any synchronization penalty for using in cases where it really wasn't needed.
从表面上看,锁省略似乎可以允许我们不必忍受同步带来的负担,就可以编写线程安全的代码了,前提是在同步的确是多余的情况下。
应用推荐