Java Advanced Feature Series--concurrent

Source: Internet
Author: User

Reprinted from Http://www.cnblogs.com/skywang12345/p/java_threads_category.html

JUC:java.util.concurrent

One, Juc Atom class

Depending on the type of data being modified, the atomic manipulation classes in the Juc package can be divided into 4 classes.

1. Basic type : Atomicinteger, Atomiclong, Atomicboolean;
2. array type : Atomicintegerarray, Atomiclongarray, Atomicreferencearray;
3. reference type : Atomicreference, Atomicstampedrerence, atomicmarkablereference;
4. object's property modification type : Atomicintegerfieldupdater, Atomiclongfieldupdater, Atomicreferencefieldupdater.

These classes exist to perform atomic operations on the corresponding data. The so-called atomic operation means that the operation process is not interrupted, and that the data operation is carried out in an atomic manner.

Atomiclong:

Atomiclong is a function of atomic manipulation of long-shaped shapes.
In 32-bit operating systems, the 64-bit long and double variables are not atomic because they are manipulated by the JVM as a two separated 32-bit. The use of Atomiclong allows long operations to remain atomic.

Example:

 Packagecom.util.concurrent.atomic;ImportJava.util.concurrent.atomic.AtomicLong; Public classAtomiclongtest { Public Static voidMain (string[] args) {//TODO auto-generated Method StubAtomiclong Matolong=NewAtomiclong (); Matolong.set (0x0123456789abcdefl); System.out.println ("ToString ()" +matolong.tostring ()); System.out.println ("Get ()" +matolong.get ()); System.out.println ("Intvalue ()" +Matolong.intvalue ()); System.out.println ("Longvalue ()" +Matolong.longvalue ()); System.out.println ("Incrementandget ()" +matolong.incrementandget ()); System.out.println ("Getandincrement ()" +matolong.getandincrement ()); System.out.println ("Decrementandget ()" +matolong.decrementandget ()); System.out.println ("Getanddecrement ()" +matolong.getanddecrement ()); System.out.println ("Get ()" +matolong.get ()); System.out.println ("Addandget ()" + Matolong.addandget (0x10)); System.out.println ("Getandadd ()" + Matolong.getandadd (0x10)); System.out.println ("Getandset ()" + Matolong.getandset (0x0123456789abcdeel)); System.out.println ("Compareandset ()" + Matolong.compareandset (0x0123456789abcdeel, 0x0123456789abcdedl)); System.out.println ("Get ()" +matolong.get ()); }}

Results:

ToString () 81985529216486895get ()81985529216486895intvalue () -1985229329longvalue () 81985529216486895incrementandget ()81985529216486896getandincrement ()81985529216486896  Decrementandget ()81985529216486896getanddecrement () 81985529216486896get () 81985529216486895addandget ()81985529216486911getandadd () 81985529216486911getandset () 81985529216486927compareandset ()trueget ()81985529216486893

Java Advanced Feature Series--concurrent

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.