public interface Buffer
{
public void set(int value) throws InterruptedException;
public int get() throws InterruptedException;
}
This is the class that implements the interface
import java.util.concurrent.ArrayBlockingQueue;
public class BlockingBuffer implements Buffer
{
private final ArrayBlockingQueue<Integer> buffer;
public BlockingBuffer()
{
buffer = new ArrayBlockingQueue<Integer>(1);
}
public void set(int value) throws InterruptedException
{
buffer.put(value);
System.out.printf("%s%2d\t%s%d\n" , "Producer writes " , value , "Buffer cells occupied: " , buffer.size());
}
public int get() throws InterruptedException
{
int readValue = 0;
readValue = buffer.take();
System.out.printf("%s %2d\t%s%d\n" , "Consumer reads " , readValue , "Buffer cells occupied: " , buffer.size());
return readValue;
}
}
This is my main method
public static void main(String args[])
{
ExecutorService application = Executors.newCachedThreadPool();
Buffer sharedLocation = new BlockingBuffer();
application.execute( new Producer( sharedLocation));
application.execute( new Consumer( sharedLocation));
application.shutdown();
}
what i want to ask is about this statement:
Buffer sharedLocation = new BlockingBuffer();
I can't understand this statement . Can an interface variable holds the reference of an object ..? Is interface acted like inheritance ..?
thanks in advance .:rolleyes:


Sign In
Create Account

Guest_R3.RyozKidz_*
Back to top









