本帖最后由 于潇 于 2012-5-18 09:51 编辑
- class MyThread extends Thread
- {
- private String name ;
- public MyThread(String name){
- this.name = name ;
- }
- public void run()
- {
- for(int i=0;i<10;i++)
- {
- System.out.println(name + "运行,i = " + i) ;
- }
- }
- };
- public class Thread01{
- public static void main(String args[]){
- MyThread mt1 = new MyThread("线程A ") ;
- MyThread mt2 = new MyThread("线程B ") ;
- mt1.run() ;
- mt2.run() ;
- }
- };
复制代码 这段代码,我的运行结果是:
两个线程没有交替运行,反而顺序执行?
|