- class Test extends Thread
- {
- private String name;
- Test(String name)
- { this.name=name; }
- public void run()
- {
- for(int x=0;x<20;x++)
- System.out.println(name+" test "+x); }
- }
- //-----------------------------------------
- class ThreadTest
- {
-
-
- public static void main(String[] args)
- {
- Test t1 =new Test( "one");
- Test t2 =new Test( "two");
- t2.start();
- t1.start();
- for(int x=0;x<20;x++)
- System.out.println("Hello World!");
- }
- }
复制代码 为什么 t2.start();
t1.start(); 无论顺序如何,结果都一样? |
-
1.jpg
(11.7 KB, 下载次数: 38)
|