阅读背景:

线程初学

来源:互联网 

class MyThread implements Runnable{
	int i = 100;
	public void run(){
		while(true){
			synchronized(this){
			//Thread.currentThread()获得当前代码在哪一个线程中运行,会返回线程对象(Thread对象)
			System.out.println(Thread.currentThread().getName() + i);
			i--;
			//让线程让出CPU,使所有线程重新竞争CPU
			Thread.yield();
			if(i<0)
				break;
			}
		}
	}
}class MyThread implements Runnable{
	int i = 100;




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: