java 多线程

View Code
 1 class MyThread extends Thread{
2 private String name;
3 public MyThread(String name){
4 this.name=name;
5 }
6 public void run(){
7 for(int i=0;i<10;i++){
8 System.out.println(name+"运行,i="+i);
9 }
10 }
11 }
12 public class ThreadDemo {
13 public static void main(String[] args) {
14 MyThread mt1=new MyThread("线程A");
15 MyThread mt2=new MyThread("线程B");
16 mt1.start();
17 mt2.start();
18 }
19
20 }


注意,用的是start方法,而不是run方法

posted @ 2012-03-12 19:40  谈笑风生膜法师  阅读(156)  评论(0编辑  收藏  举报