|
Package Com.siwuxie095.thread;
Class Myrun implements runnable{
Publicvoid run () {
For (int i = 0; i < 5; i++) {
Try {
// every time you print, Hibernate 1 seconds
Thread.Sleep (+);
// gets the current thread name
System.out.println (Thread.CurrentThread (). GetName () +"-"+i);
} catch (Interruptedexception e) {
E.printstacktrace ();
}
}
}
}
public class ThreadPriority {
< Span style= "COLOR: #b26818" >public staticvoid main (string[] args) {
< Span style= "Color:blue" >// 3 Span style= "Font-family:microsoft Yahei UI; Background-color:white "> thread object, passing in anonymous object and string ( identify thread )
Thread t1=new thread (new Myrun (),"A");
Thread t2=new thread (new Myrun (),"B");
Thread t3=new thread (new Myrun (),"C");
< Span style= "Color:blue" >// t1- minimum, t2- OK, t3- Max
// the greater the priority, the more likely it will increase T3 first execution speed, that is, the first to grab the CPU Resources
// but it's not absolutely possible .
T1.setpriority (thread.min_priority);
T2.setpriority (thread.norm_priority);
T3.setpriority (thread.max_priority);
// start this 3 Threads
T1.start ();
T2.start ();
T3.start ();
}
}
|