Java: Java中常見的線程安全的類

一、Java.util.concurrent.atomic包下的原子類 AtomicXXXX(Atomic意爲原子的)數組

例如:AtomicInteger AtomicBoolean AtomicLong安全

AtomicIntegerArray、AtomicLongArray:該類是Java對Integer數組和Long數組支持的原子性操做;atom

二、常見的集合類線程

List:Vector (效率低,不建議用)code

Map:ConcurrentHashMap HashTable ConcurrentSkipListMap繼承

Set:ConcurrentSkipListSet接口

ConcurrentSkipListSet和TreeSet,它們雖然都是有序的集合。可是,第一,它們的線程安全機制不一樣,TreeSet是非線程安全的,而ConcurrentSkipListSet是線程安全的。第二,ConcurrentSkipListSet是經過ConcurrentSkipListMap實現的,而TreeSet是經過TreeMap實現的。ip

三、可變字符串:StringBuffer也是線程安全字符串

四、BlockingQueue 和 BlockingDeque
BlockingDeque接口繼承了BlockingQueue接口, 
BlockingQueue 接口的實現類有ArrayBlockingQueue ,LinkedBlockingQueue ,PriorityBlockingQueue 而BlockingDeque接口的實現類有LinkedBlockingDeque 
BlockingQueueBlockingDeque 都是經過使用定義爲final的ReentrantLock做爲類屬性顯式加鎖實現同步的同步

相關文章
相關標籤/搜索