Java Multithreading, Concurrency, and Parallelism — Part 3

4 min readJul 6, 2021

Life Cycle of a thread with Methods in Thread Class

For managing threads in java, we have many static and instance methods in the Thread class. We can use these methods for creating, starting, pausing, and stopping threads.

Static Methods

  1. static int activeCount()
  2. static Thread currentThread()
  3. static void dumpStack()
  4. static boolean interrupted()
  5. static void sleep()
  6. static void yield()

Instance Methods

  1. void start()
  2. long getId()
  3. String getName()
  4. int getPriority()
  5. void interrupt()
  6. boolean isInterrupted()
  7. boolean isAlive()
  8. void join()
  9. String toString()

This is not the complete list and we will not even cover all of the above. There are other methods but we don’t really need them unless we build some tiny multithreading frameworks ourselves.

Here in this article, we will discuss the methods related to the lifecycle of threads in Java:start() and sleep(). We will also discuss some of the states in the thread’s lifecycle.

So, the first step is to create an instance of thread.

As you can see at line 16, we have created a Thread instance named greeterThread and we have overridden therun()method that performs the actual task. But nothing is happening yet. At this stage, all we’ve got is a plain old Java object of type Thread. It is not yet a thread of execution. A thread of execution means it has its own Execution Context: call stack, variable stack, state, pc register and etc. So it is not considered alive yet. At this stage, the thread is said to be in the NEW state. In order to make the thread alive, we have to invoke start()method on it as below.





Full Stack Tech Lead | Software Consultant | Technical Content Writer