“`” 尽量使用 tryLock(long timeout, TimeUnit unit)的方法(ReentrantLock、ReentrantReadWriteLock),设置超时时间,超时可以退出防止死锁。

尽量使用 Java. util. concurrent 并发类代替自己手写锁。

尽量降低锁的使用粒度,

尽量不要几个功能用同一把锁。

尽量减少同步的代码块。

<pre><code> "“`

Was this helpful?

0 / 0

发表回复 0

Your email address will not be published.