实现Runnable接口 实心run方法
package com.com.duoxiancheng;
public class MyRunnable implements Runnable{//接口
@Override
public void run() {
for (int i = 0; i <1000 ; i++) {
System.out.println("子线程" + i);
}
}
}
package com.com.duoxiancheng;
public class test2 {
public static void main(String[] args) {
//1先创建Runnable的对象
Runnable r = new MyRunnable();
//2创建线程对象,必须指向我的Runnable
Thread t = new Thread(r);
t.start();
for (int i = 0; i < 1000; i++) {
System.out.println("我是主线程" + i);
}
}
}