package thread; public class ThreadTest { public static void main(String args[]) { //new TestThread ().start(); TestThread tt= new TestThread();//创建TestThread类的一个实例 Thread t= new Thread(tt);//创建一个Thread类的实例 t.start();//使线程进入Runnable状态 new Thread(tt).start(); int i = 100; while(i-- > 0) { System.out.println("main thread is running"); } } } class TestThread implements Runnable //extends Thread { int ticket = 100; public void run()//线程的代码段,当执行start()时,线程从此出开始执行 { while(ticket > 0) { System.out.println(Thread.currentThread().getName() + " is running " + ticket); ticket--; } } }