Click here to Skip to main content
14,927,434 members
Home / Discussions / Java
   

Java

 
GeneralRe: ReaderWriter Problem Pin
pembepanter22-Dec-19 4:15
Memberpembepanter22-Dec-19 4:15 
GeneralRe: ReaderWriter Problem Pin
Richard MacCutchan22-Dec-19 5:02
mveRichard MacCutchan22-Dec-19 5:02 
GeneralRe: ReaderWriter Problem Pin
pembepanter23-Dec-19 1:26
Memberpembepanter23-Dec-19 1:26 
GeneralRe: ReaderWriter Problem Pin
Richard MacCutchan23-Dec-19 2:08
mveRichard MacCutchan23-Dec-19 2:08 
GeneralRe: ReaderWriter Problem Pin
Member 1472682625-Jan-20 22:13
MemberMember 1472682625-Jan-20 22:13 
AnswerRe: ReaderWriter Problem Pin
Gerry Schmitz22-Dec-19 3:20
mveGerry Schmitz22-Dec-19 3:20 
GeneralRe: ReaderWriter Problem Pin
pembepanter22-Dec-19 4:16
Memberpembepanter22-Dec-19 4:16 
QuestionJava reader writer project Pin
pembepanter10-Dec-19 22:28
Memberpembepanter10-Dec-19 22: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 MacCutchan10-Dec-19 23:04
mveRichard MacCutchan10-Dec-19 23:04 
AnswerMessage Closed Pin
16-Dec-19 18:38
MemberMember 1468932316-Dec-19 18:38 
GeneralRe: Java reader writer project Pin
Richard MacCutchan16-Dec-19 23:31
mveRichard MacCutchan16-Dec-19 23:31 
GeneralRe: Java reader writer project Pin
phil.o16-Dec-19 23:57
mvephil.o16-Dec-19 23:57 
GeneralRe: Java reader writer project Pin
Richard MacCutchan17-Dec-19 1:46
mveRichard MacCutchan17-Dec-19 1:46 
Questionjfreechar tooltip not able to show Pin
Member 23212935-Dec-19 16:42
MemberMember 23212935-Dec-19 16:42 
AnswerRe: jfreechar tooltip not able to show Pin
Richard MacCutchan5-Dec-19 22:35
mveRichard MacCutchan5-Dec-19 22:35 
QuestionWhat is a medium-size Java open source project with really well maintained automated tests? Pin
Member 146772343-Dec-19 18:49
MemberMember 146772343-Dec-19 18:49 
AnswerRe: What is a medium-size Java open source project with really well maintained automated tests? Pin
Richard MacCutchan3-Dec-19 23:19
mveRichard MacCutchan3-Dec-19 23:19 
GeneralHelp with a website written in Java Pin
Tim Kohl25-Nov-19 23:13
MemberTim Kohl25-Nov-19 23:13 
GeneralMessage Closed Pin
26-Nov-19 21:57
MemberCarla Santos Alves26-Nov-19 21:57 
GeneralRe: Help with a website written in Java Pin
Richard MacCutchan26-Nov-19 22:59
mveRichard MacCutchan26-Nov-19 22:59 
GeneralRe: Help with a website written in Java Pin
Tim Kohl27-Nov-19 21:21
MemberTim Kohl27-Nov-19 21:21 
GeneralRe: Help with a website written in Java Pin
Gerry Schmitz28-Nov-19 5:37
mveGerry Schmitz28-Nov-19 5:37 
QuestionHelp With Sorting Multidimensional String Array Pin
eskomo8424-Nov-19 6:15
Membereskomo8424-Nov-19 6:15 
AnswerRe: Help With Sorting Multidimensional String Array Pin
Richard MacCutchan24-Nov-19 6:23
mveRichard MacCutchan24-Nov-19 6:23 
GeneralRe: Help With Sorting Multidimensional String Array Pin
eskomo8424-Nov-19 6:45
Membereskomo8424-Nov-19 6: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.