When is a Java thread alive?

According to the Javadoc you mentionned:

A thread is alive if it has been started and has not yet died.

A thread “starts” when its start() method is invoked and “dies” at the end of its run() method, or when stop() (now deprecated) is invoked. So yes, a thread is “alive” when its run() method is still ongoing, but it is also “alive” in the time window between the invocation of start() and the implicit invocation of the run() method by the JVM.

You can also check the Thread.getState() and interesting information about Thread States suggested by @Marou Maroun.

I am also following his suggestion warning you that a Thread can end prematurely in case an Exception is thrown that propagates beyond run. The Thread would not be alive anymore in that case.

EDIT: As suggested by @zakkak, the thread can be considered alive even though the run() method did not start yet. In case you want to have proper control on when it will be invoked, use the ScheduledExecutorService, specifically the schedule() method which gives you more precise execution schedule.

Leave a Comment