/**
* 实现Runnable 创建多线程的简单实现
*
* @author silence
*/
public class MyRunnable implements Runnable {
@Override
public void run() {
for (int i = 0; i < 100; i++) {
//打印当前线程名
System.out.print(Thread.currentThread().getName() + " = ");
System.out.println(i);
}
}
}
=====================
/**
* 实现Runnable 创建多线程的简单实现
* @author silence
*/
public class Demo1 {
public static void main(String[] args) {
Thread t1 = new Thread(new MyRunnable());
Thread t2 = new Thread(new MyRunnable());
Thread t3 = new Thread(new MyRunnable());
t1.setName("线程1");
t1.start();
t2.setName("线程2");
t2.start();
t3.setName("线程3");
t3.start();
}
}