JAVA Runnable 实现线程,start 调用。。

JAVA Runnable 实现线程,start 调用。。
package Mian1129;

public class 线程 {

public static void main(String[] args) {
MyThread1 thread1 = new MyThread1();
thread1.start(); //我的这不能调用。不知道该怎么修改。
}
}

class MyThread1 implements Runnable {
public void run() {
for (int i = 0; i <= 100; i++) {
System.out.println("线程1执行了" + i + "次");
}
}

}
法一:new Thread(new MyThread1()).start(); ?
法二:MyThread1 thread1 = new MyThread1();
Thread t=new Thread(thread1 );
t.start();
法核链三:改掘孙
Executor executor=Executors.newCachedThreadPool() ;
executor.execute(new MyThread1());

相应的API自散如己去查吧!
← 上一篇: 下一篇: →