线程池-Executor抽象

1
2
3
public interface Executor {
void execute(Runnable command);
}

阅读全文

一些博客

awesome-list

阅读全文

ConcurrentLinkedQueue

内部类 Node

1
2
3
4
5
6
7
private static class Node<E> {
// 存储队列中的元素
volatile E item;

// next 存储单向链表,指向下一个结点
volatile Node<E> next;
}

阅读全文

CopyOnWriteArrayList

文档介绍

This is ordinarily too costly, but may be more efficient than alternatives when traversal operations vastly outnumber mutations, and is useful when you cannot or don’t want to synchronize traversals, yet need to preclude interference among concurrent threads.

阅读全文

PriorityBlockingQueue

无界的 blocking queue,因为它是 unbouned 的,所以从逻辑上来说,put 操作是不会失败的,除非内存资源被耗尽(causing OutOfMemoryError)。

不支持 null 元素。

iterator 不保证顺序。

内部使用二叉堆(binary heap)来实现维护入队元素的顺序。

阅读全文

SynchronousQueue

SynchronousQueue 是 blocking queue 队列的一种,它的作用是,当一个线程执行插入操作(put)的时候,必须等待另一个线程执行对应的删除操作(take),反之,一个线程如果要执行删除操作则必须等待另一个线程执行插入操作。

What We CAN’T DO IN SynchronousQueue:

阅读全文

并发容器-BlockingQueue(2)-LinkedBlockingQueue

BlockingQueue 的基于链表的实现

在其内部,实现中使用,two lock queue, 使用是两个锁,

1
2
3
4
5
6
7
8
9
10
11
/** Lock held by take, poll, etc */
private final ReentrantLock takeLock = new ReentrantLock();

/** Wait queue for waiting takes */
private final Condition notEmpty = takeLock.newCondition();

/** Lock held by put, offer, etc */
private final ReentrantLock putLock = new ReentrantLock();

/** Wait queue for waiting puts */
private final Condition notFull = putLock.newCondition();

阅读全文

并发容器-ConcurrentMap

ConcurrentMap

1
public interface ConcurrentMap<K, V> extends Map<K, V>

阅读全文

并发容器-BlockingQueue(1)-ArrayBlockingQueue

BlockingQueue

API

BlockingQueue methods come in four forms, with different ways of handling operations that cannot be satisfied immediately, but may be satisfied at some point in the future:

阅读全文

学习目录

##集合类

  • ArrrayList
  • HashMap
  • LinkedList

阅读全文