Universal-image-loader, there are two ways to handle a task: Fifo,lifo
In the Deque package under Core/assist, its main definition is lifolinkedblockingdeque, and the others are in Java.util and Java.util.concurr.
Let's take a look at the differences between the queue and the deque and their related classes.
1. Queue: Queues, inherited from collection, defines several queue-related methods
2. Deque: Bidirectional queue, inherited from queue, defines methods related to bidirectional operations
3. Blockingqueue: Blocking queue
4. Blockingdeque: Bidirectional blocking queue
5. Abstractqueue: Several basic methods of the queue are implemented,
6. Linkedblockingqueue: Thread safe, blocking queue, default length is Integer.max_value
Sorts the elements by FIFO (first in.). The head of the queue is the longest element in the queue. The tail of the queue is the element with the shortest time in the queue. The throughput of a linked queue is typically higher than an array-based queue.
1 /**2 * Linked List node class, one-way lists3 */4 Static classNode<e> {5 E Item;6 /**7 * One of:8 *-The real successor Node9 *-this Node, meaning the successor is Head.nextTen *-NULL, meaning there is no successor (this is the last node) One */ A -Node<e>Next; -Node (E x) {item =x;} the}View Code
7. Linkedblockingdeque: Thread-safe, two-way blocking queue, its implementation is mainly based on two node, the default length is Integer.max_value
1 /**doubly-linked List node class doubly linked list*/2 Static Final classNode<e> {3 /**4 * The item, or null if this node has been removed.5 */6 E Item;7 8 /**9 * One of:Ten *-The real predecessor Node One *-this Node, meaning the predecessor is tail A *-NULL, meaning there is no predecessor - */ -Node<e>prev; the - /** - * One of: - *-The real successor Node + *-this Node, meaning the successor is head - *-NULL, meaning there is no successor + */ ANode<e>Next; at - Node (E x) { -item =x; - } - } - in /** - * Pointer to first node to * Invariant: (first = = NULL && last = = null) | | + * (First.prev = = NULL && First.item! = null) - */ the transientNode<e>First ; * $ /**Panax Notoginseng * Pointer to last node. Tail - * Invariant: (first = = NULL && last = = null) | | the * (Last.next = = NULL && Last.item! = null) + */ A transientNode<e> last;View Code
8. Lifolinkedblockingdeque: LIFO, bidirectional blocking queue, only override two methods
1 @Override2 Public BooleanOffer (T e) {3 return Super. Offerfirst (e);4 }5 6 /**7 * Retrieves and removes the first element of this deque. This method differs the from {@link#pollFirst Pollfirst} only8 * In that it throws a exception if this deque is empty.9 * Ten * @returnThe head of this deque One * @throwsnosuchelementexception A * If this deque is empty - */ - @Override the PublicT Remove () { - return Super. Removefirst (); -}View Code
How blocking queues work: one thread (producer) puts a task, another thread (consumer) takes out the task
Reference Link: http://www.cnblogs.com/qiengo/archive/2012/12/19/2824971.html
Android Open source framework: Universal-image-loader parsing (iv) taskprocess