Android Multithreading Research (1) Threading Basics and Source code analysis

Source: Internet
Author: User

From today, let's take a look at Android's multithreaded knowledge, Android is easy to get started, but it's not easy to do a perfect product, so let's start with the thread and step into Android.

First, thread based review

Package com.maso.test;  
         The first way to create the public class Traditionalthread {public static void main (string[] args) {* * * thread  
                */Thread Thread1 = new Thread () {@Override public void run () {  
                try {sleep (1000);  
                catch (Interruptedexception e) {e.printstacktrace ();  
                } while (true) {System.out.println (Thread.CurrentThread (). GetName ());  
        }  
            }  
        };  
              
        Thread1.start ();  
                  
            * * * The second way to create a thread thread2 = new Thread (new Runnable () {  
                @Override public void Run () {try {thread.sleep (1000);  
              catch (Interruptedexception e) {e.printstacktrace ();  } while (true) {System.out.println (Thread.CurrentThread (). GetName ());  
        }  
            }  
        });  
              
        Thread2.start ();
            * * thread's call priority/new Thread (new Runnable () {@Override  
                public void Run () {try {thread.sleep (1000);  
                catch (Interruptedexception e) {e.printstacktrace ();  
                } while (true) {System.out.println ("Runnable"); }} {public void run () {try {1000  
                );  
                catch (Interruptedexception e) {e.printstacktrace ();  
                } while (true) {System.out.println ("Thread");  
      }      };  
    }.start (); }  
}

The code above is two ways of creating threads that are familiar to us, and if you're unfamiliar with them, look at the Java Thread Basics first.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

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.