public class SharedQueue { private class Link { public Object item; public Link next; public Link(Object i) { item=i; next=null; } } private Link head, tail; public SharedQueue() { head=null; tail=null; } public synchronized void add(Object i) { if (head==null) { head=new Link(i); tail=head; } else { Link temp=new Link(i); tail.next=temp; tail=temp; } } public synchronized boolean empty() { return (head==null); } public synchronized Object remove() { if (head==null) return (null); Object result=head.item; head=head.next; return (result); } public synchronized Object first() { if (head==null) return (null); return (head.item); } }