![]()
1 package hello2;
2 /**
3 * 每个线程均输出20次消息数字、“你好”、线程名
4 * @author L
5 *
6 */
7 public class MyThread implements Runnable {
8
9 @Override
10 public void run() {
11 // TODO Auto-generated method stub
12 for (int i = 0; i < 20; i++) {
13 Thread t = Thread.currentThread();
14 System.out.println((i + 1) + ".你好,来自线程" + t.getName());
15 }
16 }
17 }
1 package hello2;
2
3 public class Main {
4 public static void main(String[] args) {
5 Thread t1=new Thread(new MyThread());
6 Thread t2=new Thread(new MyThread());
7 t1.start();
8 t2.start();
9 }
10 }
![]()
![]()