First entry multithreaded sample show--runner

Source: Internet
Author: User
Tags thread class

Multi-person race process with Multithreading: Runnerthread.java
 Packagethread;/*** All the people coming to the race, using threads to write 100 threads? * Create a new player thread * 1. Player name * 2. Thread name *@authorSuperdrew **/ Public classRunnerthreadextendsthread{PrivateString Runnername;//player Name    PrivateString ThreadName;//Thread Name         Publicrunnerthread (String runnername,string threadname) {Super(ThreadName);//passing the thread name to the parent class         This. Runnername =Runnername; }         Public voidrun () { while(true) {System.out.println ( This. runnername+ "Leading the ... "+" Current thread: "+ This. GetName ()); }    }}    
Test thread Runnergame.java
 Packagethread;/*** Different people come to compete with a thread class that produces different thread objects * Running race *@authorsuperdrew * * 1. Inherit thread * 2. Implement runnable interface via Thread.Start (); * Run is thread body*/ Public classRunnergame { Public Static voidMain (string[] args) {//the contestants are here.Runnerthread Rt1 =NewRunnerthread ("Mark", "Mark_thread"); Runnerthread Rt2=NewRunnerthread ("Bob", "Bob_thread"); Runnerthread RT3=NewRunnerthread ("Lily", "Lily_thread"); Runnerthread RT4=NewRunnerthread ("GenY", "Geny_thread"); Runnerthread Rt5=NewRunnerthread ("King", "King_thread"); //run offRt1.start ();        Rt2.start ();        Rt3.start ();        Rt4.start ();    Rt5.start (); }}

First-entry multithreaded sample show--runner

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.