1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| Thread threadA = new Thread(() -> { System.out.println("线程A开始执行"); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("线程A执行完毕"); });
Thread threadB = new Thread(() -> { System.out.println("线程B开始执行"); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("线程B执行完毕"); });
threadA.start(); threadB.start();
try { threadB.join(); } catch (InterruptedException e) { e.printStackTrace(); }
System.out.println("主线程执行完毕");
|