简体   繁体   中英

Is it safe to call thread.start() if the thread is in TERMINATED state?

A thread that I am running in my web application returns TERMINATED when I call the thread.getState()

Is it safe for me to check the status through thread.isAlive() and call the thread.start() on a new object of the same class?

What should be the value of thread.isAlive() for me to start the terminated thread again?

I see threads as disposable/one-shot workers, they do a simple job and then they get killed.

The TERMINATED state is associated with an object. As long as you're using start() on a different (new) object, it's fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM