I have a question though. The current code allows the following to
happen:
Thread A calls topEQ.push(newEQ) and topEQ.push executes partially but
doesn't execute this line:
newEventQueue.prev = this;
So at this point, newEQ.prev is still null (unless it was already
initialized before push was called; that shouldn't happen, but if it
did, the current code could give weird results). If Thread B calls
newEQ.pop and executes the lines:
if (prev == null)
throw new EmptyStackException();
then Thread B will get an EmptyStackException, even though the method
call to push newEQ was issued before newEQ's pop call. Is that
acceptable behaviour or should there be more synchronization to ensure
that push completes on topEQ before pop can be called on newEQ?