本帖最后由 李涛兴 于 2012-11-16 23:01 编辑
- class Ticket implements Runnable
- {
- private int tick=100;
- Object obj=new Object();
- public void run()
- {
- while(true)
- {
- synchronized(obj)
- {
- if(tick>0)
- {
- try
- {
- Thread.sleep(10);
- }
- catch(Exception e)
- {
- }
- System.out.println(Thread.currentThread().getName()+".."+tick--);
- }
- }
- }
- }
- }
- class TicketDemo
- {
- public static void main(String[] args)
- {
- Ticket t=new Ticket();
- //t.run();
- 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();
-
- }
- }
复制代码 请问线程为什么使用异常try{},catch{}的时候,而不用使该类去继承Exception或者RuntimeException呢?
|