Back
Close

Computing with Data

elgeish
82.2K views

Deadlocks - Part I

Here's another example for issues that can occur due to lock objects being visible outside the enclosing class where they belong:

class A implements Runnable {
public void run() {
synchronized (A.class) {
System.out.println("A has A.class and now wants B.class");
try {
Thread.sleep(500); // simulates some work being done
} catch (InterruptedException ex) {
System.out.println(ex);
}
synchronized (B.class) {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants