|
JavaTM Platform Standard Ed. 6 |
|||||||||
��һ�������� ��һ�������� | ��� ��� ������ |
����
����
��ժҪ | |
---|---|
AtomicBoolean | ������ԭ�ӷ�ʽ���µ� boolean ֵ�� |
AtomicInteger | ������ԭ�ӷ�ʽ���µ� int ֵ�� |
AtomicIntegerArray | ������ԭ�ӷ�ʽ������Ԫ�ص� int ���顣 |
AtomicIntegerFieldUpdater<T> | ���ڷ����ʵ�ù��ߣ����Զ�ָ�����ָ�� volatile int �ֶν���ԭ�Ӹ��¡� |
AtomicLong | ������ԭ�ӷ�ʽ���µ� long ֵ�� |
AtomicLongArray | ������ԭ�ӷ�ʽ������Ԫ�ص� long ���顣 |
AtomicLongFieldUpdater<T> | ���ڷ����ʵ�ù��ߣ����Զ�ָ�����ָ�� volatile long �ֶν���ԭ�Ӹ��¡� |
AtomicMarkableReference<V> | AtomicMarkableReference ά�����б��λ�Ķ������ã�����ԭ�ӷ�ʽ������и��¡� |
AtomicReference<V> | ������ԭ�ӷ�ʽ���µĶ������á� |
AtomicReferenceArray<E> | ������ԭ�ӷ�ʽ������Ԫ�صĶ����������顣 |
AtomicReferenceFieldUpdater<T,V> | ���ڷ����ʵ�ù��ߣ����Զ�ָ�����ָ�� volatile �ֶν���ԭ�Ӹ��¡� |
AtomicStampedReference<V> | AtomicStampedReference ά��������������־���Ķ������ã�������ԭ�ӷ�ʽ������и��¡� |
���С���߰���֧���ڵ��������Ͻ�������̰߳�ȫ��̡���ʵ�ϣ��˰��е���ɽ� volatile ֵ���ֶκ�����Ԫ�صĸ�����չ����ЩҲ�ṩԭ���������²������࣬����ʽ���£�
boolean compareAndSet(expectedValue, updateValue);
����˷������ڲ�ͬ������������Ҳ��ͬ����ǰ���� expectedValue������ԭ�ӷ�ʽ����������Ϊ updateValue�����ڳɹ�ʱ���� true���˰��е��������ȡ������������ֵ�ķ������Լ����������Ľ���������ԭ�Ӹ��²��� weakCompareAndSet��
��Щ�����Ĺ淶ʹʵ���ܹ�ʹ�õ������������ṩ�ĸ�Ч��������ԭ��ָ�������ijЩƽ̨�ϣ���֧�ֿ�����Ҫij����ʽ���ڲ�����������÷��������ϸ�֤�������� - ִ�в���֮ǰ������ʱ�����̡߳�
�� AtomicBoolean
��AtomicInteger
��AtomicLong
�� AtomicReference
��ʵ�������ṩ����Ӧ���͵��������ķ��ʺ��¡�ÿ����ҲΪ�������ṩ�ʵ���ʵ�ù��߷��������磬�� AtomicLong �� AtomicInteger �ṩ��ԭ������������һ��Ӧ�ó������·�ʽ�������кţ�
class Sequencer { private final AtomicLong sequenceNumber = new AtomicLong(0); public long next() { return sequenceNumber.getAndIncrement(); } }
ԭ�ӷ��ʺ��µ��ڴ�Ч��һ����ѭ���¿ɱ�������� The Java Language Specification, Third Edition (17.4 Memory Model) �е�������
���˰�����ʾ����ֵ����֮�⣬�˰������� Updater �࣬��������ڻ�ȡ����ѡ���������ѡ�� volatile �ֶ��ϵ� compareAndSet ������AtomicReferenceFieldUpdater
��AtomicIntegerFieldUpdater
�� AtomicLongFieldUpdater
�ǻ��ڷ����ʵ�ù��ߣ������ṩ�Թ����ֶ����͵ķ��ʡ�������Ҫ����ԭ�����ݽṹ�У��ýṹ��ͬһ�ڵ㣨���磬���ڵ�����ӣ��ļ��� volatile �ֶζ�������ԭ�Ӹ��¿��ơ���Щ��������Լ���ʱʹ��ԭ�Ӹ��·�����и��������ԣ�����Ӧ�ı��ǻ���ӳ������ý�Ϊ����ʹ�ò�̫���㣬�����ڱ�֤����Ҳ�ϲ
AtomicIntegerArray
��AtomicLongArray
�� AtomicReferenceArray
���һ����չ��ԭ�Ӳ���������Щ���͵������ṩ��֧�֡���Щ����Ϊ������Ԫ���ṩ volatile �������巽��Ҳ����עĿ���������ͨ������˵�Dz���֧�ֵġ�
AtomicMarkableReference
�ཫ��������ֵ�����ù������������磬���������ݽṹ�ڲ�ʹ�ô�λ������ζ�����õĶ����������ѱ�ɾ����AtomicStampedReference
�ཫ����ֵ�����ù������������磬������ڱ�ʾ�����ϵ�ж�Ӧ�İ汾�š�
���ԭ������Ҫ�������ֹ���飬����ʵ�ַ��������ݽṹ����صĻ����ṹ�ࡣcompareAndSet �����������ij����滻�����������������Ҫ������������ ����ʱ��Ӧ������
ԭ����� java.lang.Integer ��������ͨ���滻������������ �������� hashCode �� compareTo ֮��ķ���������Ϊԭ�ӱ����ǿɱ�ģ����Զ��ڹ�ϣ������˵�����Dz��Ǻõ�ѡ�����⣬��Ϊ��Щͨ����Ԥ��Ӧ�ó�����ʹ�õ������ṩ�ࡣ���磬û�б�ʾ byte ��ԭ���ࡣ������������������Ҫ������������ʹ�� AtomicInteger ������ byte ֵ���������ʵ���ǿ��ת����Ҳ����ʹ�� Float.floatToIntBits �� Float.intBitstoFloat ת�������� float ֵ��ʹ�� Double.doubleToLongBits �� Double.longBitsToDouble ת�������� double ֵ��
|
JavaTM Platform Standard Ed. 6 |
|||||||||
��һ�������� ��һ�������� | ��� ��� ������ |
��Ȩ���� 2007 Sun Microsystems, Inc. ��������Ȩ���� ����������֤��������������ĵ����·ַ�������