Code example for PriorityBlockingQueue

0
    void init(Handler handler, int threadPoolSize) {
        mHandler = handler;
        mItemStates = Collections.synchronizedMap(new WeakHashMap<View, ItemState<Params>>());
        mItemRequests = new ConcurrentHashMap<String, ItemRequest<Params, Result>>(8, 0.9f, 1);
        mExecutorService = new ItemsThreadPoolExecutor<Params, Result>(threadPoolSize, threadPoolSize, 60,
                TimeUnit.SECONDS, new PriorityBlockingQueue<Runnable>());
    } 
 
    void performDisplayItem(View itemContainer, Adapter adapter, View itemView, long timestamp) {
        final ItemState<Params> itemState = getItemState(itemView);
        if (!itemState.shouldLoadItem) {
            if (ENABLE_LOGGING) {
                Log.d(LOGTAG, "Item should not load, bailing: " + itemState.itemParams);
            } 
 
            return; 
        } 
 
        final Params itemParams = itemState.itemParams;
        if (itemParams == null) {
            if (ENABLE_LOGGING) {