Java Program for a Deadlock

public class DeadLock{ public static void main(String[] args) throws InterruptedException { final Object obj = new Object(); final Object obj1 = new Object(); Thread t = new Thread() { public void run() { while (true) { synchronized (obj) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } synchronized (obj1) { } } } } }; t.start(); while (true) { synchronized (obj1) { Thread.sleep(1000); synchronized (obj) { } } } } }



Comments

Popular posts from this blog

JMeter – Working with JSON

How to create an XML Log file in Java using JAXB (Customized)

Hyperlocal Startups Creating a Better Living