说来挺傻的,写了个new Thread().start()就没想到,在没有执行到start那一步之前,还是走的单线程啊,顺序执行下来,你start方法写在后面当然就后执行啊。
然后把start往前一提,就变成交叉执行输出了。
package com.thread.simple; public class ThreadOne extends Thread { @Override public void run() { for (int i = 0; i < 10; i ++) { System.out.println("sub" + i); } } public static void main(String[] args) throws InterruptedException { Thread thread = new ThreadOne(); thread.start(); for (int i = 0; i < 10; i ++) { System.out.println("main--" + i); // Thread.sleep((int) (Math.random() * 1000)); } } }