package test;class TestThread extends Thread{ public void run(){ for(int n=0;n<3;n++) { try{Thread.sleep(1000);}//线程休息毫秒 catch(InterruptedException e){e.printStackTrace();} System.out.println("n="+n); }}}
package test;public class Testlianxithread { public static void main(String[] args) { TestThread tt = new TestThread(); tt.start();// 启动多线程 TestThread tt2 = new TestThread(); tt2.start(); TestThread tt3 = new TestThread(); tt3.start(); }}
输出结果为每隔1000毫秒输出