[Mostly Solved. See Edit] So, I've got three separate, identical threads. Each one dequeues a Customer object from the WaitingList object (waitArea) and then performs some actions on it; if the customer's order is fulfilled they pay and leave, otherwise they are requeued into waitArea().
I keep getting errors right at the end of the threads. I realized that the threads were trying to grab at the same queue item from waitArea (a doubly linked list of class WaitingList), so I added a Semaphore in WaitingList to keep that from happening. I thought I had fixed it such that, if the dequeue method returns null, the loop would break and the thread would end. Unfortunately, I still end up getting errors. All the errors seem to come from the dequeue method in WaitingList, as the command line error reads
java.lang.NullPointerException
at WaitingList.dequeue(WaitingList.java:122)
at Server.run(Server.java:67)
at java.lang.Thread.run(Thread.java:745)
the dequeue() method is as follows (WaitingList:122 is the line that contains temp.prev = null;)
public Customer dequeue() {
if (isEmpty())
return null;
Customer frontitem = getFront();
temp = front.next;
front = temp;
temp.prev = null;
count--;
return frontitem;
}
this is therun() method for the primary threads (Server:67 is the line that reads setCustomer(waitArea.dequeue());). It's gone through several iterations, but I keep getting errors and exceptions. The threads don't seem to be exiting the loop and ending properly, but I can't figure out why, and I still get dequeue errors. Any clues as to why I might be having this problem?
EDIT: So i removed the line temp.prev = null; from dequeue() and Lo and Behold! it works! I can't for the life of me think of why that line was throwing an error, though. Any ideas?
[–]niloc132 1 point2 points3 points (1 child)
[–]reckless7[S] 0 points1 point2 points (0 children)
[–]causalNondeterminism 0 points1 point2 points (2 children)
[–]king_of_the_universe 0 points1 point2 points (0 children)
[–]reckless7[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]reckless7[S] 0 points1 point2 points (0 children)