本文转自:http://xuyuanshuaaa.iteye.com/blog/1109498

 

            }
        }
    }
}
package org.demo.runnable;
public class RunnableTicket {
    public static void main(String[] args) {
        MyThread mt=new MyThread();
        new Thread(mt).start();//同一个mt,但是在Thread中就不可以,如果用同一
        new Thread(mt).start();//个实例化对象mt,就会出现异常
        new Thread(mt).start();
    }
};
虽然现在程序中有三个线程,但是一共卖了10张票,也就是说使用Runnable实现多线程可以达到资源共享目的。

Runnable接口和Thread之间的联系:
public class Thread extends Object implements Runnable
发现Thread类也是Runnable接口的子类。

 

相关文章: