O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

Using this rule, you will avoid deadlock situations. For example, in the case presented earlier, you can change operation2() to first get lock1 and then lock2. Now if both operation1() and operation2() execute their respective first sentences, one of them will be blocked waiting for lock1 and the other will get lock1 and lock2 and they will do their operations. After this, the blocked thread will get the lock1 and lock2 locks and it will do its operation.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required