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