Click here to Skip to main content
14,459,361 members
   

Java

 
GeneralRe: ReaderWriter Problem Pin
pembepanter22-Dec-19 5:15
Memberpembepanter22-Dec-19 5:15 
GeneralRe: ReaderWriter Problem Pin
Richard MacCutchan22-Dec-19 6:02
communityengineerRichard MacCutchan22-Dec-19 6:02 
GeneralRe: ReaderWriter Problem Pin
pembepanter23-Dec-19 2:26
Memberpembepanter23-Dec-19 2:26 
GeneralRe: ReaderWriter Problem Pin
Richard MacCutchan23-Dec-19 3:08
communityengineerRichard MacCutchan23-Dec-19 3:08 
GeneralRe: ReaderWriter Problem Pin
Member 1472682625-Jan-20 23:13
MemberMember 1472682625-Jan-20 23:13 
AnswerRe: ReaderWriter Problem Pin
Gerry Schmitz22-Dec-19 4:20
mveGerry Schmitz22-Dec-19 4:20 
GeneralRe: ReaderWriter Problem Pin
pembepanter22-Dec-19 5:16
Memberpembepanter22-Dec-19 5:16 
QuestionJava reader writer project Pin
pembepanter10-Dec-19 23:28
Memberpembepanter10-Dec-19 23:28 
Hi I have a project but I do not have an an idea about the topic. Can you help me or give any resources about that topic?
This is my project:
In this project you will need to provide a solution to readers-writers problem in which several processes (readers and writers) are trying to access shared variables. Obviously, if two readers access the shared data simultaneously, no adverse effects will result, hence, they are allowed to access. However, if a writer and some other process (either a reader or a writer) access the data simultaneously, chaos may ensue. To ensure that these difficulties do not arise, we require that the writers have exclusive access to the shared data while writing to the data.
The solution must guarantee that:
If a writer has begun writing process, then
No additional writer can perform write function
No reader is allowed to read
If 1 or more readers are reading, then
Other readers may read as well
No writer may perform write function until all readers have finished reading

You are given Test class that use ReadWriteLock class and threads for the problem. You are expected to use Semaphore provided in the code.
Two operations on the semaphore is allowed; acquire() and release()
To do:
Implement methods of ReadWriteLock class given.

Also this my code test.java

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();

}
}


}


Thank you
AnswerRe: Java reader writer project Pin
Richard MacCutchan11-Dec-19 0:04
communityengineerRichard MacCutchan11-Dec-19 0:04 
AnswerMessage Closed Pin
16-Dec-19 19:38
MemberMember 1468932316-Dec-19 19:38 
GeneralRe: Java reader writer project Pin
Richard MacCutchan17-Dec-19 0:31
communityengineerRichard MacCutchan17-Dec-19 0:31 
GeneralRe: Java reader writer project Pin
phil.o17-Dec-19 0:57
mvephil.o17-Dec-19 0:57 
GeneralRe: Java reader writer project Pin
Richard MacCutchan17-Dec-19 2:46
communityengineerRichard MacCutchan17-Dec-19 2:46 
Questionjfreechar tooltip not able to show Pin
Member 23212935-Dec-19 17:42
MemberMember 23212935-Dec-19 17:42 
AnswerRe: jfreechar tooltip not able to show Pin
Richard MacCutchan5-Dec-19 23:35
communityengineerRichard MacCutchan5-Dec-19 23:35 
QuestionWhat is a medium-size Java open source project with really well maintained automated tests? Pin
Member 146772343-Dec-19 19:49
MemberMember 146772343-Dec-19 19:49 
AnswerRe: What is a medium-size Java open source project with really well maintained automated tests? Pin
Richard MacCutchan4-Dec-19 0:19
communityengineerRichard MacCutchan4-Dec-19 0:19 
GeneralHelp with a website written in Java Pin
Tim Kohl26-Nov-19 0:13
MemberTim Kohl26-Nov-19 0:13 
GeneralMessage Closed Pin
26-Nov-19 22:57
MemberCarla Santos Alves26-Nov-19 22:57 
GeneralRe: Help with a website written in Java Pin
Richard MacCutchan26-Nov-19 23:59
communityengineerRichard MacCutchan26-Nov-19 23:59 
GeneralRe: Help with a website written in Java Pin
Tim Kohl27-Nov-19 22:21
MemberTim Kohl27-Nov-19 22:21 
GeneralRe: Help with a website written in Java Pin
Gerry Schmitz28-Nov-19 6:37
mveGerry Schmitz28-Nov-19 6:37 
QuestionHelp With Sorting Multidimensional String Array Pin
eskomo8424-Nov-19 7:15
Membereskomo8424-Nov-19 7:15 
AnswerRe: Help With Sorting Multidimensional String Array Pin
Richard MacCutchan24-Nov-19 7:23
communityengineerRichard MacCutchan24-Nov-19 7:23 
GeneralRe: Help With Sorting Multidimensional String Array Pin
eskomo8424-Nov-19 7:45
Membereskomo8424-Nov-19 7:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.