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.
要是您想用一小块线程安全代码把要求同步的两个操作隔开,那么只使用一个同步块一般会更好些。
If it is not small enough, you should analyze your code and refactor it in such a way that anything that could run asynchronously is located outside of the synchronized block.
如果同步代码块不够小,应该对代码进行分析,对其重构,以使所有可以异步运行的代码均位于同步代码块之外。
In light of our observation it seems as if we should be able to optimize access in the case where a thread is looping over a synchronized block of code.
根据我们的观察,我们似乎需要对一些锁的访问进行优化,比如线程执行的同步块代码在一个循环体中。
应用推荐