private static void addListToHead(PspGeList list) { lock (drawListQueue) { // The ConcurrentLinkedQueue type doesn't allow adding // objects directly at the head of the queue. // This function creates a new array using the given list as it's head // and constructs a new ConcurrentLinkedQueue based on it. // The actual drawListQueue is then replaced by this new one. int arraySize = drawListQueue.size(); if (arraySize > 0) { PspGeList[] array = drawListQueue.toArray(new PspGeList[arraySize]); ConcurrentLinkedQueue <PspGeList> newQueue = new ConcurrentLinkedQueue <PspGeList>(); PspGeList[] newArray = new PspGeList[arraySize + 1]; newArray[0] = list; for (int i = 0; i < arraySize; i++) { newArray[i + 1] = array[i]; newQueue.add(newArray[i]); } drawListQueue = newQueue; } else { // If the queue is empty. drawListQueue.add(list); } } }