问题:为什么线程名称为Thread-1的线程没有被成功创建?
为什么线程名称为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(); }} }