Producer Consumer Program in Java

//ProducerConsumer Class
public class ProducerConsumer {
    int count = 0;
    LinkedList<Integer> list = new LinkedList<>();
    public void consume() throws InterruptedException {
        while (true) {
            synchronized (this) {
                while (list.size() == 0)
                    wait();
                int val = list.removeFirst();
                System.out.println("Consumed Element is " + val);
                notify();
                Thread.sleep(1000);
            }
        }
    }

    public void produce() throws InterruptedException {
        while (true) {
            synchronized (this) {
                while (list.size() >= 3) {
                    wait();
                }
                list.add(count);
                System.out.println("Produced Element is " + count);
                count++;
                notify();
                Thread.sleep(1000);
            }
        }
    }
}

//Driver Class

public class Driver {

    public static void main(String[] args) {
        ProducerConsumer producerConsumer = new ProducerConsumer();
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    producerConsumer.produce();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    producerConsumer.consume();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t1.start();
        t2.start();
    }
}