Java 使用匿名类创建线程时 无法调用start() 如何开启进程

    new Runnable (){
        public void run(){
            for ( int i = 0 ; i < 10 ; i ++ )
                System.out.println(Thread.currentThread().getName()+":"+i);
        }
    }.**start()**;

    new Thread (){
        public void run(){
            for ( int i = 0 ; i < 10 ; i ++ )
                System.out.println(Thread.currentThread().getName()+":"+i);
        }
    }.start();

new Thread (
new Runnable (){
public void run(){
for ( int i = 0 ; i < 10 ; i ++ )
System.out.println(Thread.currentThread().getName()+":"+i);
}
}).start();

问题已经解决,Runnable的实现作为参数就可以创建进程了。学艺不精,见笑了。

两种方法:
1.使用Thread thread = new Thread(Runnable task)
thread.start();//这是使用Thread的有参构造函数
2.使用线程池
ExecutorService service = Executors.newFixedThreadPool(10);//10表示启动的线程个数
service.execute(Runnable task);