多线程---yield



--多线程优先级

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();
		}
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值