Android Multithreading Research (7) thread concurrency library in Java5

Source: Internet
Author: User
Tags thread

Starting from this article we'll look at the new API for threading that we added after Java 5, and first look at the API documentation:

Java.util.concurrent contains many thread-safe, well tested, high-performance concurrent building blocks, let's look at the Atomicinteger under the atomic package first.

Import Java.util.concurrent.atomic.AtomicInteger;  
      
public class Atomicintegertest {  
    private static atomicinteger data = new Atomicinteger (0);  
    public static void Main (string[] args {  
        new Thread () {new Runnable () {  
                  
            @Override public
            void Run () {  
                data.i Ncrementandget ();  Plus  
            }  
        }). Start ();  
              
        New Thread (New Runnable () {  
                  
            @Override public
            void Run () {  
                data.decrementandget ();  Minus  
            }  
        }). Start ();  
    }  
}

Using Atomicinteger can be a convenient implementation of data sharing between threads, and if a member variable is to be manipulated by multiple threads, it can be handled using Atomicinteger, and other data types have corresponding atomic.

Related Article

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.