import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class DeadlockUsingSemaphore {
final static Lock lock1 = new ReentrantLock();
final static Lock lock2 = new ReentrantLock();
public static void main(String[]args)
{
Thread t1 = new Thread(new Runnable3());
t1.setName("First Thread");
t1.start();
Thread t2 = new Thread(new Runnable4());
t2.setName("Second Thread");
t2.start();
}
static class Runnable3 implements Runnable
{
public void run()
{
DeadlockUsingSemaphore.lock1.lock();
try
{
System.out.println(Thread.currentThread().getName() + ": acquired
lock1. Trying for lock2...");
try
{
Thread.sleep(500);
}catch(InterruptedException e){ e.printStackTrace(); }
DeadlockUsingSemaphore.lock2.lock();
try
{
System.out.println(Thread.currentThread().getName() + ": acquired
lock2.");
} finally {
DeadlockUsingSemaphore.lock2.unlock();
}
}finally{
DeadlockUsingSemaphore.lock1.lock();
}
}
}
static class Runnable4 implements Runnable
{
public void run()
{
DeadlockUsingSemaphore.lock2.lock();
try
{
System.out.println(Thread.currentThread().getName() + ": acquired
lock2. Trying for lock1...");
try
{
Thread.sleep(500);
}catch(InterruptedException e){ e.printStackTrace(); }
DeadlockUsingSemaphore.lock1.lock();
try
{
System.out.println(Thread.currentThread().getName() + ": acquired
lock1.");
}finally{
DeadlockUsingSemaphore.lock1.unlock();
}
}finally{
DeadlockUsingSemaphore.lock2.unlock();
}
}
}
}
****************************************************************** SCREENSHOT *********************************************************

Java programming Exercise 32.11 Write a program that uses explicit locks (or semaphores) to cause a deadlock. Do not us...
Prelab Exercises Your task is to write a Java program that will print out the following message (including the row of equal marks): Computer Science, Yes!!!! ========================= An outline of the program is below. Complete it as follows: a. In the documentation at the top, fill in the name of the file the program would be saved in and a brief description of what the program does. b. Add the code for the main method to do the printing. //...