Code example for Queue

Methods: add, poll, size

0
			LoadImgCallable callable,int width,int height){
		Queue<WeakReference<Future<Bitmap>>> requestList = requestMap
				.get(context);
		if (requestList == null) {
			requestList = new LinkedList<WeakReference<Future<Bitmap>>>();
			requestMap.put(context, requestList);
		} 
 
		/* 
		 * 若当前context的请求队列大于requestTaskSizePerContext, 则出队最前面的请求 
		 */ 
		if (requestList.size() >= requestTaskSizePerContext) {
			WeakReference<Future<Bitmap>> futureWR = requestList.poll();
			if (futureWR != null && futureWR.get() != null) {
				try { 
					futureWR.get().cancel(true);
				} catch (Exception e) {
					e.printStackTrace();
				} 
			} 
		} 
 
		if (threadPool == null) {
			threadPool = getThreadPool();
			if (imageCache == null) {
				imageCache = new ImageCache();
			} 
		} 
 
		Future request = threadPool.submit(new GetImageLoad(position, url,callable,height,height));
		requestList.add(new WeakReference<Future<Bitmap>>(request));
		 
//		System.out.println("-------==========-------getActiveCount "+((ThreadPoolExecutor)threadPool).getActiveCount() 
//				+"-------==========-------getQueue "+((ThreadPoolExecutor)threadPool).getQueue().size());