Click here to Skip to main content
14,427,368 members
   

Java

 
PinnedForum Guidelines - PLEASE READ PinPopular
Chris Maunder28-Jul-09 3:36
cofounderChris Maunder28-Jul-09 3:36 
QuestionMessage Closed Pin
20-Jan-20 15:21
Memberbekagaw65320-Jan-20 15:21 
AnswerMessage Closed Pin
20-Jan-20 15:22
Memberbekagaw65320-Jan-20 15:22 
JokeJ Pin
Member 1471420112-Jan-20 10:03
MemberMember 1471420112-Jan-20 10:03 
SuggestionRe: Java task zigzag Pin
Richard MacCutchan12-Jan-20 23:11
communityengineerRichard MacCutchan12-Jan-20 23:11 
AnswerRe: Java task zigzag Pin
ZurdoDev13-Jan-20 2:05
mveZurdoDev13-Jan-20 2:05 
GeneralRe: Java task zigzag Pin
Richard MacCutchan13-Jan-20 2:33
communityengineerRichard MacCutchan13-Jan-20 2:33 
Questionbus reservation and ticketting system Pin
Member 1469715023-Dec-19 11:20
MemberMember 1469715023-Dec-19 11:20 
AnswerRe: bus reservation and ticketting system Pin
Richard MacCutchan23-Dec-19 22:32
communityengineerRichard MacCutchan23-Dec-19 22:32 
AnswerRe: bus reservation and ticketting system Pin
ZurdoDev13-Jan-20 2:06
mveZurdoDev13-Jan-20 2:06 
Questionproject on java Pin
Member 1469715023-Dec-19 3:53
MemberMember 1469715023-Dec-19 3:53 
AnswerRe: project on java Pin
Richard MacCutchan23-Dec-19 4:20
communityengineerRichard MacCutchan23-Dec-19 4:20 
AnswerMessage Closed Pin
17-Jan-20 0:57
MemberMember 1471908117-Jan-20 0:57 
QuestionReaderWriter Problem Pin
pembepanter21-Dec-19 11:38
Memberpembepanter21-Dec-19 11:38 
QuestionRe: ReaderWriter Problem Pin
Richard MacCutchan21-Dec-19 22:38
communityengineerRichard MacCutchan21-Dec-19 22:38 
AnswerRe: ReaderWriter Problem Pin
pembepanter22-Dec-19 0:17
Memberpembepanter22-Dec-19 0:17 
GeneralRe: ReaderWriter Problem Pin
phil.o22-Dec-19 4:43
mvephil.o22-Dec-19 4:43 
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 
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 

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.