FileDocCategorySizeDatePackage
MsgQueue.javaAPI DocExample737Tue Jan 28 17:16:30 GMT 1997None

MsgQueue.java

// This example is from the book _Java Threads_ by Scott Oaks and Henry Wong. 
// Written by Scott Oaks and Henry Wong.
// Copyright (c) 1997 O'Reilly & Associates.
// You may study, use, modify, and distribute this example for any purpose.
// This example is provided WITHOUT WARRANTY either expressed or implied.

// Sample MsgQueue -- Chapter 5, p. 88.

import java.util.*;

public class MsgQueue {
    Vector queue = new Vector();
    public synchronized void send(Object obj) {
        queue.addElement(obj);
    }

    public synchronized Object recv() {
        if (queue.size() == 0) return null;

        Object obj = queue.firstElement();
        queue.removeElementAt(0);
        return obj;
    }
}