ITeye博客

问题:为什么线程名称为Thread-1的线程没有被成功创建?

hoonee · 2014-05-15 21:05 · JavaSE · 编程语言 · Markdown

为什么线程名称为Thread-1的线程没有被成功创建?

package com.hoonee.javase.thread;

import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; /**

  • Callable 用法举例

  • @author Hoonee

  • @mail hoonee@163.com */ public class FirstCallable implements Callable{

    @Override public Integer call() throws Exception { int i = 0; for(; i < 100; i++) { System.out.println(Thread.currentThread().getName() + "-" + i); } return null; }

    public static void main(String args) {

     FirstCallable callable = new FirstCallable();
     FutureTask<Integer> task = new FutureTask<Integer>(callable);
    
     for(int i = 0; i < 100; i++)
     {
     	System.out.println(Thread.currentThread().getName() + "-" + i);
     	if(i == 20)
     	{
     		new Thread(task,"Thread-0").start();
     		//为什么线程名称为Thread-1的线程没有被成功创建
     		new Thread(task,"Thread-1").start();
     	}
     }
    
     try {
     	System.out.println(task.get());
     } catch (InterruptedException e) {
     	e.printStackTrace();
     } catch (ExecutionException e) {
     	e.printStackTrace();
     }
    

    } }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。