Learn thread 1 to build threads and start

Source: Internet
Author: User

First step: Build the Thread class and start the thread

1 /**2 * "1" implements the Runnable interface, overriding the Run method. 3 * The logic code inside the "2" Run method is the thread body4 * "3" creates an object of the thread class5 * "4" creates a proxy object for the thread class6 * "5" proxy object called Start (), Start thread7  * @authorit-c-12018  *9  */Ten  Public classMyThreadImplementsrunnable{ One  A     //Thread Body -      Public voidrun () { -          for(inta=0;a<100;a++){ theSystem.out.println ("Mythread.run (thread body run)" +a); -         } -          -     } +  -      +      Public Static voidMain (string[] args) { A         //create a real role. object of the thread body itself atMyThread mythread=NewMyThread (); -         //Create a static proxy role -Thread dailimythread=NewThread (myThread); -         //Start Thread - Dailimythread.start (); -          in          for(inta=0;a<100;a++){ -System.out.println ("Mythread.main (Main method)" +a); to         } +     } -      the      *}
View Code

Step two: Show test results

1Mythread.main (Main method) 02Mythread.run (thread body run) 03Mythread.run (thread body run) 14Mythread.run (thread body run) 25Mythread.run (thread body run) 36Mythread.main (Main method) 17Mythread.main (Main method) 28Mythread.main (Main method) 39Mythread.main (Main method) 4TenMythread.main (Main method) 5 OneMythread.main (Main method) 6 AMythread.main (Main method) 7 -Mythread.main (Main method) 8 -Mythread.main (Main method) 9 theMythread.main (Main method) 10 -Mythread.main (Main method) 11 -Mythread.main (Main method) 12 -Mythread.main (Main method) 13 +Mythread.run (thread body run) 4 -Mythread.run (thread body run) 5 +Mythread.run (thread body run) 6 AMythread.main (Main method) 14 atMythread.main (Main method) 15 -Mythread.main (Main method) 16 -Mythread.main (Main method) 17 -Mythread.main (Main method) 18 -Mythread.main (Main method) 19 -Mythread.run (thread body run) 7 inMythread.main (Main method) 20 -Mythread.main (Main method) 21 toMythread.main (Main method) 22 +Mythread.main (Main method) 23 -Mythread.run (thread body run) 8 theMythread.main (Main method) 24 *Mythread.main (Main method) 25 $Mythread.run (thread body run) 9Panax NotoginsengMythread.main (Main method) 26 -Mythread.run (thread body run) 10 theMythread.main (Main method) 27 +Mythread.main (Main method) 28 AMythread.main (Main method) 29 theMythread.main (Main method) 30 +Mythread.main (Main method) 31 -Mythread.main (Main method) 32 $Mythread.main (Main method) 33 $Mythread.main (Main method) 34 -Mythread.main (Main method) 35 -Mythread.run (thread body run) 11 theMythread.main (Main method) 36 -Mythread.run (thread body run) 12WuyiMythread.main (Main method) 37 theMythread.run (thread body run) 13 -Mythread.main (Main method) 38 WuMythread.run (thread body run) 14 -Mythread.main (Main method) 39 AboutMythread.run (thread body run) 15 $Mythread.main (Main method) 40 -Mythread.run (thread body run) 16 -Mythread.main (Main method) 41 -Mythread.run (thread body run) 17 AMythread.main (Main method) 42 +Mythread.run (thread body run) 18 theMythread.main (Main method) 43 -Mythread.run (thread body run) 19 $Mythread.main (Main method) 44 theMythread.run (thread body run) 20 theMythread.main (Main method) 45 theMythread.run (thread body run) 21 theMythread.main (Main method) 46 -Mythread.run (thread body run) 22 inMythread.main (Main method) 47 theMythread.run (thread body run) 23 theMythread.main (Main method) 48 AboutMythread.run (thread body run) 24 theMythread.main (Main method) 49 theMythread.run (thread body run) 25 theMythread.main (Main method) 50 +Mythread.run (thread body run) 26 -Mythread.main (Main method) 51 theMythread.run (thread body run) 27BayiMythread.main (Main method) 52 theMythread.run (thread body run) 28 theMythread.main (Main method) 53 -Mythread.run (thread body run) 29 -Mythread.main (Main method) 54 theMythread.run (thread body run) 30 theMythread.main (Main method) 55 theMythread.run (thread body run) 31 theMythread.main (Main method) 56 -Mythread.run (thread body run) 32 theMythread.main (Main method) 57 theMythread.run (thread body run) 33 theMythread.main (Main method) 58
View Code

Learn thread 1 to build threads and start

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.