1.

What is a Thread in Java? Can we start a dead thread again?

Answer»

A thread in Java is the path that is followed when a program is executed. There is atleast ONE thread in all Java programs that is created by the JVM at the start of the program. This is known as the main thread. The java.lang.Thread class CREATES and CONTROLS all the Java threads.

The thread life cycle in Java contains 5 states. These are given below:

  1. New
  2. Runnable
  3. Running
  4. Blocked (Non-runnable)
  5. Terminated

Can a dead thread be started again in Java?

It is not possible to start a thread after it has completed execution i.e. after it is dead a thread cannot be BROUGHT to runnable state.

It is better to start a new instance. The actions that need to be executed should be wrapped in the Runnable interface and then the Runnable can be passed to the new instance of Thread.



Discussion

No Comment Found