Question: public class ConcurrencyManagementExample { private static final Object lock 1 = new Object ( ) ; private static final Object lock 2 = new Object
public class ConcurrencyManagementExample
private static final Object lock new Object;
private static final Object lock new Object;
private static final Object lock new Object;
public static void mainString args
Thread thread new Thread
synchronized lock
System.out.printlnThread acquired lock;
try
Thread.sleep;
catch InterruptedException e
eprintStackTrace;
synchronized lock
System.out.printlnThread acquired lock;
Critical section
;
Thread thread new Thread
synchronized lock
System.out.printlnThread acquired lock;
try
Thread.sleep;
catch InterruptedException e
eprintStackTrace;
synchronized lock
System.out.printlnThread acquired lock;
Critical section
;
threadstart;
threadstart;
What is the most likely output from running above program?
The screen show the following println lines:
Thread acquired lock;
Thread acquired lock;
Thread acquired lock;
Thread acquired lock;
The screen show the following println lines:
Thread acquired lock;
Thread acquired lock;
Thread acquired lock;
Thread acquired lock;
or
Thread acquired lock;
Thread acquired lock;
Thread acquired lock;
Thread acquired lock;
deadlock or livelock
The st thread is starved because the nd thread holds the lock and is sleeping, thus delaying thread from acquiring lock
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
