Runnable接口创建线程的实现方法
工具/原料
MyEclipse
创建实现类MyRunnable
1、创建实现类并取名为MyRunnable
2、点击Add按钮来实现接口
3、输入runnable选择第一个
4、点击finish完成后来到代码编辑窗口
5、重写run方法,写上一个获取线程名的方法
测试代码
1、创建测试类test,并创建MyRunnable thread1的实例
2、创建MyRunnable thread2的实例
3、创建Thread th1的实例(在创建实例的同时已经通过构造参数把线程的名字修改为My thred1)
4、创建Thread th2的实例(在创建实例的同时已经通过构造参数把线程的名字修改为My thred2)
5、启动所有线程
6、最后控制台显示结果为Mythread1 和Mythread2