Can someone help me with debugging this error?
This is the error Im getting but I do not know why.
SharedBufferTest.java:16: cannot find symbol
symbol : constructor Producer(Buffer)
location: class Producer
Producer producer = new Producer( sharedLocation );
^
SharedBufferTest.java:17: cannot find symbol
symbol : constructor Consumer(Buffer)
location: class Consumer
Consumer consumer = new Consumer( sharedLocation );
Here is the code for SharedBufferTest.java
public class SharedBufferTest { public static void main( String [] args) { Buffer sharedLocation = new UnsynchronizedBuffer(); Producer producer = new Producer( sharedLocation ); Consumer consumer = new Consumer( sharedLocation ); Semaphore valueProduced=new Semaphore(0); Semaphore valueConsumed = new Semaphore(1); producer.start(); consumer.start(); } }
Here is the Producer code
public class Producer extends Thread{ private Buffer sharedLocation; private Semaphore valueProduced; private Semaphore valueConsumed; public Producer (Buffer shared, Semaphore valueP, Semaphore valueC) { super("Producer"); sharedLocation = shared; valueProduced = valueP; valueConsumed = valueC; } public void run() { for (int count = 1; count <= 4; count++){ //try { //Thread.sleep((int) (Math.random() * 3001)); valueConsumed.P(); //check to see if the value has been consumed P( valueConsumed ); sharedLocation.set(count); //let consumer thread know it can consume the value valueProduced.V(); //} //catch (InterruptedException exception) { //exception.printStackTrace(); //} } System.err.println(getName() + " done producing."); } }
Here is the Consumer code
public class Consumer extends Thread{ private Buffer sharedLocation; private Semaphore valueProduced; private Semaphore valueConsumed; public Consumer (Buffer shared, Semaphore valueP, Semaphore valueC) { super("Consumer"); sharedLocation = shared; valueProduced = valueP; valueConsumed = valueC; } public void run() { int sum = 0; for (int count=1; count<=4; count++) { //try{ //how it shouldve worked: //sharedLocation.get()=null; check to see if the buffer is empty //if //Thread.sleep((int) (Math.random() * 3001)); valueProduced.P(); sum += sharedLocation.get(); valueConsumed.V(); //} //catch (InterruptedException exception) { //exception.printStackTrace(); //} } System.err.println(getName() + " done consuming. and sum= " + sum); } }