看这个代码 你再理解一下- package com.itheima.test2;
- class ThreadRunn implements Runnable{
-
- public void run(){
- while(true){
- System.out.println(Thread.currentThread().getName()+"run().....");
- }
- }
- }
- public class RunnableTest {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- //建立ThreadRunn 的子类对象
- ThreadRunn tr = new ThreadRunn();
-
- //将子类对象作为参数传递给Thread
- Thread t1 = new Thread(tr);
- Thread t2= new Thread(tr);
-
- //开启线程
- t1.start();
- t2.start();
-
-
-
-
- }
- }
复制代码 |