Runnable接口实现多线程

class MyThreadimplements Runnable{

         private String title;

         public MyThread(String title){

                   this.title = title;

         }

         @Override

         public void run(){

                   for(int i = 1; i <=50;i++){

                            System.out.println(title+"-----"+i);

                   }                

         }

}

 

public classTestDemo {

         public static void main(String[] args){

                   MyThread mt1 = newMyThread("线程A");

                   MyThread mt2 = newMyThread("线程B");

                   MyThread mt3 = newMyThread("线程C");

                  

                   new Thread(mt1).start();

                   new Thread(mt2).start();

                   new Thread(mt3).start();

         }

}

注:使用Runnable接口可以更加方便的表示出数据共享的概念。