+/EE360P

distributed systems

git clone https://git.julia.blue/+/EE360P

Wei-Lun Hungadd chap. 2 and 3df69975

master
690 B28 linesraw
1public class ListQueue {
2    class Node {
3        public String data;
4        public Node next;
5    }
6    Node head = null, tail = null;
7    public synchronized void enqueue(String data) {
8        Node temp = new Node();
9        temp.data = data;
10        temp.next = null;
11        if (tail == null) {
12            tail = temp;
13            head = tail;
14        } else {
15            tail.next = temp;
16            tail = temp;
17        }
18        notify();
19    }
20    public synchronized String dequeue() {
21        while (head == null)
22            Util.myWait(this);
23        String returnval = head.data;
24	if (head == tail) tail = null;
25        head = head.next;
26        return returnval;
27    }
28}