Blocking and non-blocking queue I came up with the following for a blocking and non-blocking queue implementation. Please suggest any changes/improvements/gotchas.

Blocking queue:

public class BlockingQueue&lt;T&gt; {
    List&lt;T&gt; buffer;
    private static final int MAX_QUEUE_SIZE = 100;

    public BlockingQueue() {
        buffer = new ArrayList&lt;T&gt;();
    }

    public void enqueue(T value) throws InterruptedException {
        synchronized(buffer) {
            while(buffer.size() &gt;= MAX_QUEUE_SIZE) {
                buffer.wait();
            }
            buffer.add(value);
            buffer.notifyAll();
        }
    }

    public T dequeue() throws InterruptedException {
        synchronized(buffer) {
            while(buffer.size() &lt; 1) {
                buffer.wait();
            }
            T value = buffer.remove(0);
            buffer.notifyAll();
            return value;
        }
    }

}


Non-blocking queue:

public class NonBlockingQueue&lt;T&gt; {
    List&lt;T&gt; buffer;
    private static final int MAX_QUEUE_SIZE = 100;
    private AtomicBoolean mutex = new AtomicBoolean(false);

    public NonBlockingQueue() {
        buffer = new ArrayList&lt;T&gt;();
    }

    public void enqueue(T value) throws InterruptedException {
        while(true) {
            while(!mutex.compareAndSet(false, true)) {
                Thread.sleep(100);
            }
            if(buffer.size() &lt; MAX_QUEUE_SIZE) {
                buffer.add(value);
                mutex.set(false);
                return;
            } else {
                mutex.set(false);
            }
        }

    }

    public T dequeue() throws InterruptedException {
        T value = null;
        while(true) {
            while(!mutex.compareAndSet(false, true)) {
                Thread.sleep(100);
            }
            if(buffer.size() &gt; 0) {
                value = buffer.remove(0);
                mutex.set(false);
                return value;
            } else {
                mutex.set(false);
            }
        }   
    }
}


I think by non-blocking it means that the thread should not be blocked, so I used the sleep method. Please let me know if it has any issues.
You asked for critique ....


Why are you trying to use an AtomicBoolean as a mutex?  Use a primitive lock, or a Lock if you need more sophisticated behavior.
(Almost) any time you use sleep in an algorithm, you are doing it the wrong way.  In this case, the "wrong way" is a direct consequence of point 1. above.
If you want good performance in a situation where you have multiple producers and consumers, you should avoid doing a notifyAll.  For instance if there are N consumers waiting, and a producer adds a queue entry, then all N consumers will be woken up.  Ideally, only one consumer should be woken.