Code example for PriorityBlockingQueue

-1
            else 
                return null; 
        } 
    } 
 
    private static PriorityBlockingQueue<AsyncRequest> requestQueue = new PriorityBlockingQueue<AsyncRequest>(10,
            new AsyncRequest.Comparator()); 
    private static Set<String> namedRequests = new HashSet<String>();
 
    private static class AsyncRequestRunner implements Runnable {
        public void run() { 
            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
            AsyncRequest request = null;
            while (true && !Thread.interrupted()) {
                try { 
                    if (requestQueue.size() > 0) { // there seems to be a bug inside blockingqueue where in some cases an empty queue causes an exception
                        request = requestQueue.take();
                        if (request != null) {
                            synchronized (requestQueue) {
                                namedRequests.remove(request.label());
                            }