--多线程优先级
public static void yield()
yield()方法:
暂停当前正在执行的线程对象,并执行其他线程
setPriority(int newPriority):更改线程优先级
int getPriority() 返回线程的优先级。
String toString() 返回该线程的字符串表示形式,包括线程名称、优先级和线程组
(1)MAX_PRIORITY:最高优先级(10 级)
(1)Min_PRIORITY:最低优先级(1 级)
(1)Morm_PRIORITY:默认优先级(5 级)
package java.thread;
/**
*
*/
public class ThreadDemo1 {
public static void main(String[] args) {
MyThread t1 = new MyThread("t1") ;
MyThread t2 = new MyThread("t2") ;
t1.start();
t2.start();
}
}
class MyThread extends Thread{
private String name0 ;
public String getName0() {
return name0;
}
public void setName0(String name0) {
this.name0 = name0;
}
public MyThread(String name0){
this.name0 = name0 ;
}
public void run() {
for(int i = 0 ; i < 100 ; i ++){
System.out.println(name0 + " : " + i);
//放弃cpu强占权
Thread.yield();
}
}
}