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

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

How do you determine if a thread is running?

相关标签:
10条回答
  • 2020-11-28 12:05

    Check the thread status by calling Thread.isAlive.

    0 讨论(0)
  • 2020-11-28 12:08

    Thread.isAlive()

    0 讨论(0)
  • 2020-11-28 12:09

    You can use: Thread.currentThread().isAlive();. Returns true if this thread is alive; false otherwise.

    0 讨论(0)
  • 2020-11-28 12:11

    I think you can use GetState(); It can return the exact state of a thread.

    0 讨论(0)
  • 2020-11-28 12:12

    To be precise,

    Thread.isAlive() returns true if the thread has been started (may not yet be running) but has not yet completed its run method.

    Thread.getState() returns the exact state of the thread.

    0 讨论(0)
  • 2020-11-28 12:15

    Have your thread notify some other thread when it’s finished. This way you’ll always know exactly what’s going on.

    0 讨论(0)
提交回复
热议问题