日期:2014-05-20 浏览次数:20901 次
for(int i=0,j=list.size();i<j;i++){
Thread t = new xxxThread(xx);
t.start();
}
//该如何计算第一个线程开始和最后一个线程结束;
public static void main(String[] args) {
        ThreadGroup thGroup = new ThreadGroup("MyTest");
        
        long startTs = System.currentTimeMillis();
        for(int i=0;i<10;i++){
            final int id = i;
            Thread subThread = new Thread(thGroup, new Runnable(){
                // Create a thread which will run random time 0~5 sec.
                public void run() {
                    int myId = id;
                    int sec = (int) (Math.random()*5000);
                    try {
                        Thread.sleep(sec);
                    } catch (InterruptedException e) {
                    }
                    System.out.printf("Thread %d runed %f sec\n", myId, sec/1000.0);
                }
            });
            subThread.start();
        }
        // wait all thread down.