package chapter03; public class Test01 { public static void main(String[] args) { //串行执行:多个线程连接成串,然后按照顺序执行 //并非执行:多个线程是独立的,誰抢到了CPU的执行权,誰就能执行 Mythread1 t1 = new Mythread1(); Mythread2 t2 = new Mythread2(); t1.start(); try{ t1.join(); } catch (InterruptedException e) { } t2.start(); try{ t2.join(); } catch (InterruptedException e) { } System.out.println(Thread.currentThread().getName()); } } class Mythread1 extends Thread{ @Override public void run() { System.out.println(Thread.currentThread().getName()); } } class Mythread2 extends Thread{ @Override public void run() { System.out.println(Thread.currentThread().getName()); }
java的线程串行和并行执行
最新推荐文章于 2024-07-22 14:15:06 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)