实现Runnable接口
作者:互联网
- 定义TestThread类实现Runnable接口
- 实现run()方法,编写线程执行体
- 创建线程对象,调用start()方法启动线程
package com.thread.test4;
public class TestThread implements Runnable{
@Override
public void run() {
for (int i = 0; i < 200; i++) {
System.out.println("我在执行代码"+i);
}
}
//main线程,主线程
public static void main(String[] args) {
//创建实现类对象
TestThread testThread = new TestThread();
//创建代理类对象
// Thread thread = new Thread(testThread);
// //启动
// thread.start();
//等价于
new Thread(testThread).start();
for (int i = 0; i < 1000; i++) {
System.out.println("我在学习多线程"+i);
}
}
}
标签:Runnable,实现,接口,start,线程,testThread,new,public,TestThread 来源: https://www.cnblogs.com/wakeuplb/p/16203393.html