package test42;
/***
* 方式2:实现Runnable接口
* 步骤:
* A:自定义类MyRunnable实现Runnable接口
* B:重写run()方法
* C:创建MyRunnable类的对象
* D:创建Thread类的对象,并把C步骤的对象作为构造参数传递
* @author samsung
*
*/
public class test42 {
public static void main(String[] args) {
MyRunnable s=new MyRunnable();
Thread t1=new Thread(s,"消息1");
Thread t2=new Thread(s,"消息2");
t1.start();
t2.start();
}
}
class MyRunnable implements Runnable {
@Override
public void run() {
for(int x=0;x<100;x++) {
System.out.println(Thread.currentThread().getName()+":"+x);
}
}
}