Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 main
(
String
[
]
args
)
{
ExecutorService executorService
=
Executors.newCachedThreadPool
(
)
;
ReadWriteLock RW
=
new ReadWriteLock
(
)
;
executorService.execute
(
new Writer
(
RW
)
)
;
executorService.execute
(
new Writer
(
RW
)
)
;
executorService.execute
(
new Writer
(
RW
)
)
;
executorService.execute
(
new Writer
(
RW
)
)
;
executorService.execute
(
new Reader
(
RW
)
)
;
executorService.execute
(
new Reader
(
RW
)
)
;
executorService.execute
(
new Reader
(
RW
)
)
;
executorService.execute
(
new Reader
(
RW
)
)
;
}
}
class ReadWriteLock
{
private Semaphore S
=
new Semaphore
(
1
)
;
public void readLock
(
)
{
}
public void writeLock
(
)
{
}
public void readUnLock
(
)
{
}
public void writeUnLock
(
)
{
}
}
class Writer implements Runnable
{
private ReadWriteLock RW
_
lock;
public Writer
(
ReadWriteLock rw
)
{
RW
_
lock
=
rw;
}
public void run
(
)
{
while
(
true
)
{
RW
_
lock.writeLock
(
)
;
RW
_
lock.writeUnLock
(
)
;
}
}
}
class Reader implements Runnable
{
private ReadWriteLock RW
_
lock;
public Reader
(
ReadWriteLock rw
)
{
RW
_
lock
=
rw;
}
public void run
(
)
{
while
(
true
)
{
RW
_
lock.readLock
(
)
;
RW
_
lock.readUnLock
(
)
;
}
}
}
this is the test.java mentioned in the question.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions