Is it safe to lock multiple ReentrantReadWriteLocks in the same try block?
问题 Let's say I have two critial resources, foo and bar. I protect them with some ReentrantReadWriteLocks ReentrantReadWriteLock foo = new RRWL() ... ReentrantReadWriteLock bar = new RRWL() ... Most operations only use foo OR bar, but some of them happen to use both. Now when using a single lock, you can't just do this: void foo() { foo.writeLock().lock(); privateWorkOnFoo(); foo.writeLock().unlock(); } If an exception is thrown, your foo will become forever locked. Instead you wrap it, like void