In Java, how do you determine if a thread is running?

后端 未结 10 2208
-上瘾入骨i
-上瘾入骨i 2020-11-28 11:30

How do you determine if a thread is running?

10条回答
  •  醉酒成梦
    2020-11-28 12:16

    You can use this method:

    boolean isAlive()
    

    It returns true if the thread is still alive and false if the Thread is dead. This is not static. You need a reference to the object of the Thread class.

    One more tip: If you're checking it's status to make the main thread wait while the new thread is still running, you may use join() method. It is more handy.

提交回复
热议问题