本帖最后由 relice 于 2014-11-25 12:00 编辑
//下面的是单核的所以可以看到输出时的区别效果
- class Demo
- {
- public static void main(String[] args)
- {
- for(int x=0; x<=60; x++)
- {
- System.out.println("Main run"+x);
- }
- new Sub().start();
- }
- }
- class Sub extends Thread
- {
- public void run()
- {
- for(int x=0; x<=20; x++)
- System.out.println("Sub0 run"+x);
- }
- }
复制代码 //由于本机是2核的,因此至少要建立3条线程才可以看到效果- class Demo
- {
- public static void main(String[] args)
- {
- for(int x=0; x<=60; x++)
- {
- System.out.println("Main run"+x);
- }
- new Sub().start();
- new Sub2().start();
- new Sub3().start();
- }
- }
- class Sub extends Thread
- {
- public void run()
- {
- for(int x=0; x<=20; x++)
- System.out.println("Sub0 run"+x);
- }
- }
- class Sub2 extends Thread
- {
- public void run()
- {
- for(int x=0; x<=20; x++)
- System.out.println("Sub0 run"+x);
- }
- }
- class Sub3 extends Thread
- {
- public void run()
- {
- for(int x=0; x<=20; x++)
- System.out.println("Sub0 run"+x);
- }
- }
复制代码
|