java课件:第8章线程.pptVIP

  • 4
  • 0
  • 约2.81万字
  • 约 78页
  • 2019-12-25 发布于湖南
  • 举报
* * * * * * * class Player1 extends Thread //1号游戏者的类 { private Balls ball; public Player1(Balls b) { this.ball=b; } public void run() { while(true) { while(ball.flag0==true){}; ball.flag0=true; while(ball.flag2==true){}; if(ball.flag0==true ball.flag2==false) { ball.flag2=true; System.out.println(Player1 has got two balls!); ball.flag0=false; ball.flag2=false; try{ sleep(1);}catch(Exception e){}; } } } } 8.2 线程的生命周期 8.2.2 死锁问题 (续) ——例8-12 * class Player2 extends Thread //2号游戏者的类 { private Balls ball; public Player2(Balls b

文档评论(0)

1亿VIP精品文档

相关文档