按理说catch后应该不能加代码的啊。为啥第136个视频的例子会是如下
- class Tickets implements Runnable{
- private int ticks=100;
- Object o=new Object();
- public void run()
- {
- while(true)
- // synchronized(o){
- if(ticks>0)
- try{Thread.sleep(10);}catch(Exception e){}
- System.out.println(Thread.currentThread().getName()+"...sale:"+ticks--);
- // }
- }
- }
- public class TickDemo2 {
- public static void main(String[] args) {
- Tickets t=new Tickets();
-
- Thread t1=new Thread(t);
- Thread t2=new Thread(t);
- Thread t3=new Thread(t);
- Thread t4=new Thread(t);
- t1.start();
- t2.start();
- t3.start();
- t4.start();
-
- }
- }
复制代码 |
|