Question: package sync; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Semaphore; public class Test { public static void main ( String [ ] args ) { ExecutorService executorService
package sync;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
public class Test
public static void mainString args
ExecutorService executorService Executors.newCachedThreadPool;
ReadWriteLock RW new ReadWriteLock;
executorService.executenew WriterRW;
executorService.executenew WriterRW;
executorService.executenew WriterRW;
executorService.executenew WriterRW;
executorService.executenew ReaderRW;
executorService.executenew ReaderRW;
executorService.executenew ReaderRW;
executorService.executenew ReaderRW;
class ReadWriteLock
private Semaphore Snew Semaphore;
public void readLock
public void writeLock
public void readUnLock
public void writeUnLock
class Writer implements Runnable
private ReadWriteLock RWlock;
public WriterReadWriteLock rw
RWlock rw;
public void run
while true
RWlock.writeLock;
RWlock.writeUnLock;
class Reader implements Runnable
private ReadWriteLock RWlock;
public ReaderReadWriteLock rw
RWlock rw;
public void run
while true
RWlock.readLock;
RWlock.readUnLock;
this is the test.java mentioned in the question.
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
