Understanding join() method example

前端 未结 4 469
野趣味
野趣味 2020-12-15 08:22

The Java thread join() method confuses me a bit. I have following example

class MyThread extends Thread {
    private String name;
    private int sleepTime;         


        
4条回答
  •  我在风中等你
    2020-12-15 09:04

    What actually confuses you about Thread.join()? You haven't mentioned anything specific.

    Given that Thread.join() (as the documentation states), Waits for this thread to die, then t4 will wait for t3 to complete, which will wait for t2 to complete, which will wait for t1 to complete.

    Therefore t1 will complete first, followed by t2, t3, and t4.

提交回复
热议问题