多线程一例

public class TestThread implements Runnable{

    public TestThread() {
    }

    public static void main(String[] args) {
        Thread[] t = new Thread[10];
        TestThread r = new TestThread();
        for(int i=0;i<10;i++) {
            t[i] = new Thread(r);
            t[i].start();
        }
        Boolean over = false;
        while (!over){
            over = true;
            for(int i=0;i<10;i++) {
                if (t[i].isAlive()) over = false;
                break;
            }
            
        }
        System.out.println("ok");
    }

    @Override
    public void run() {
        for(int i=0;i<=10;i++) {
            System.out.println(Thread.currentThread().getName()+" "+i);
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
原文地址:https://www.cnblogs.com/qqjue/p/2630663.html