Well, when it comes to threading applications, we need to know the creation of threads first. Threads are created in two ways: first, inherit the thread class two, declare the implementation of the Runnable method
Method One:
Packagethread;//inherit the thread class Public classPracticethreadextendsThread { Public intjudge; PublicPracticethread (intjudge) { Super(); This. Judge =judge; } @Override Public voidrun () {if(Judge < 0) { for(Charch = ' a '; Ch < ' z '; ch++) {System.out.print (" " +ch); } } Else { for(Charch = ' A '; Ch < ' Z '; ch++) {System.out.print (" " +ch); } } }}
Method Two:
Packagethread; Public classPracticethreadtImplementsRunnable { Public intjudge; PublicPracticethreadt (intjudge) { Super(); This. Judge =judge; } @Override Public voidrun () {if(Judge < 0) { for(Charch = ' a '; Ch < ' z '; ch++) {System.out.print (" " +ch); } } Else { for(Charch = ' A '; Ch < ' Z '; ch++) {System.out.print (" " +ch); } } }}
There are two ways to start a thread:
Packagethread; Public classTest {/** * @paramargs*/ Public Static voidMain (string[] args) {//TODO auto-generated Method StubPracticethread pt =NewPracticethread (0) ; Practicethread pt2=NewPracticethread (-1) ; /*Thread implementation Method one*/Pt.start (); Pt2.start (); /*Thread Implementation Method two*/ NewThread (PT). Start (); NewThread (PT2). Start (); for(inti = 0; I < 5; i++) {Banzhuan<Object> BZ =NewBanzhuan<object> (5); Bz.start (); } }}
We know how to create and start a thread, so we need to know that the thread is also a priority. The lowest priority is: min_priority (1) The default priority is: Norm_priobity (5) The highest priority is: Max_priobity (10) Line Cheng think: thread-(0-max)-such as: Thread1, Thread2 .....
The simple application of multithreading