Java4Android(Mars)

Java4Android(Mars)

5 (61人评价)
  • 课时:(48)

  • 学员:(480)

  • 浏览:(29520)

  • 加入课程

Java4Android 38 Java中的线程-3的笔记

相关课时: 笔记详情:

class ThreadSync implements Runnable{
public void run(){
int i = 100;
while(true){
synchronized(this){
System.out.println(Thread.currentThread().getName() + i );
i--;
Thread.yield();
if(i < 0){
break;
}
}
}
}

public static void main(String args[]){
ThreadSync ts = new ThreadSync();
Thread t1 = new Thread(ts);
Thread t2 = new Thread(ts);
t1.setName("线程a");
t2.setName("线程b");
t1.start();
t1.yield();
t2.start();
}
}

0 0

你感兴趣的课程

8万+浏览/ 916学员/ 4.5评分
免费
6万+浏览/ 177学员/ 5评分
免费
6万+浏览/ 972学员/ 4.8评分
免费