public class Test2 {
public static void main(String[] args) {
MyRunnable mr = new MyRunnable();
Thread t = new Thread(mr);
//启动
t.start();
try {
for (int i = 0; i < 10; i++) {
Thread.sleep(1000);
System.out.println("main:"+i);
}
} catch (Exception e) {
// TODO: handle exception
}
}
}
public class MyRunnable implements Runnable{
public void run() {
try {
for (int i = 0; i < 10; i++) {
Thread.sleep(1000);
System.out.println("run:"+i);
}
} catch (Exception e) {
// TODO: handle exception
}
}
}
实现Runnable接口
最新推荐文章于 2022-11-08 16:34:00 发布