Bounded-Buffer with a TimerTask

Discussion in 'Java' started by antonioatt@yahoo.it, Jun 21, 2007.

  1. Guest

    I have a Producer/Consumer (or Bounded-Buffer) Problem.
    Here the code:

    public class Buffer<T>{
    int n;
    T[] buffer;
    int in=0,out=0,count=0;
    public Buffer(int n){
    this.n=n;buffer=new T[n];
    }
    public synchronized T get(){
    while(count==0)
    try{wait();}catch(InterruptedException e){}
    T risp=buffer[out];out=(out+1)%n;count--;
    notifyAll();
    return risp;
    }
    public synchronized void put(T value){
    while(count==n)
    try{wait();}catch(InterruptedException e){}
    buffer[in]=value;in=(in+1)%n;count++;
    notifyAll();
    }
    }

    I must modify using Timer e TimerTask
    the get method :
    public T get(long timeout) throws TimeoutException
    If get riceive from buffer before timeout OK elsewere it terminate
    throwing a TimeoutException.
    Someone can help me ! tanks
     
    , Jun 21, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John C. Bollinger
    Replies:
    0
    Views:
    483
    John C. Bollinger
    Aug 18, 2003
  2. Liz

    TimerTask priority

    Liz, Apr 17, 2004, in forum: Java
    Replies:
    3
    Views:
    3,131
    Roedy Green
    Apr 18, 2004
  3. Replies:
    0
    Views:
    301
  4. Szabolcs Ferenczi

    Fast lock-based FIFO alias bounded buffer

    Szabolcs Ferenczi, Mar 21, 2008, in forum: C++
    Replies:
    23
    Views:
    1,714
    Chris Thomasson
    Mar 22, 2008
  5. Larry

    bounded buffer

    Larry, Jan 23, 2010, in forum: C++
    Replies:
    2
    Views:
    447
    Larry
    Jan 25, 2010
Loading...

Share This Page