Example usage for java.util.concurrent BlockingQueue toArray

List of usage examples for java.util.concurrent BlockingQueue toArray

Introduction

In this page you can find the example usage for java.util.concurrent BlockingQueue toArray.

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.

Usage

From source file:org.apache.cassandra.concurrent.ContinuationsExecutor.java

/**
 * Drains the task queue into a new list, normally using drainTo. But if the
 * queue is a DelayQueue or any other kind of queue for which poll or
 * drainTo may fail to remove some elements, it deletes them one by one.
 *//*from  ww  w. j ava 2  s.  c o m*/
private List<Runnable> drainQueue() {
    BlockingQueue<Runnable> q = workQueue;
    List<Runnable> taskList = new ArrayList<Runnable>();
    q.drainTo(taskList);
    if (!q.isEmpty()) {
        for (Runnable r : q.toArray(new Runnable[0])) {
            if (q.remove(r))
                taskList.add(r);
        }
    }
    return taskList;
}