answersLogoWhite

0

Life cycle of thread in java?

Updated: 8/9/2023
User Avatar

Wiki User

15y ago

Best Answer

# New state - After the creations of Thread instance the thread is in this state but before the start() method invocation. At this point, the thread is considered not alive.

# Runnable (Ready-to-run) state - A thread start its life from Runnable state. A thread first enters runnable state after the invoking of start() method but a thread can return to this state after either running, waiting, sleeping or coming back from blocked state also. On this state a thread is waiting for a turn on processor. # Running state - A thread is in running state that means the thread is currently executing. There are several ways to enter in Runnable state but there is only one way to enter in Running state: the scheduler select a thread from runnable pool.

# Dead state - A thread can be considered dead when its run() method completes. If any thread comes on this state that means it cannot ever run again. # Blocked - A thread can enter in this state because of waiting the resources that are hold by another thread.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

Different states of a thread are :

New state - After the creations of Thread instance the thread is in this state but before the start() method invocation. At this point, the thread is considered not alive.

Runnable (Ready-to-run) state - A thread start its life from Runnable state. A thread first enters runnable state after the invoking of start() method but a thread can return to this state after either running, waiting, sleeping or coming back from blocked state also. On this state a thread is waiting for a turn on the processor.

Running state - A thread is in running state that means the thread is currently executing. There are several ways to enter in Runnable state but there is only one way to enter in Running state: the scheduler select a thread from runnable pool.

Dead state - A thread can be considered dead when its run() method completes. If any thread comes on this state that means it cannot ever run again.

Bocked - A thread can enter in this state because of waiting the resources that are hold by another thread.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Life cycle of thread in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Life cycle of a thread in java?

A thread can be any of the following states during its lifecyclenew - just createdrunnable - ready to runrunningwaiting/blocked - waiting for some operationdead


Describe the Life cycle of a thread in java.?

Life cycle of a thread New: when a thread is not yet initialized, it is in New state Runnable or Ready : Once the thread is initialized and its start method is called, then the thread becomes ready for execution, which is otherwise called runnable or ready state Not Runnable : When a thread is asked to sleep for some time or wait for some time by using the sleep or wait method, thread goes to Not Runnable state for the specified time. Dead state: Once the thread is executed,it turns to dead state. Hope this would answer your question. let me know if you are still not clear


In relation to Java what is a thread?

A Java Thread is a thread of execution in a Java Program. A Java Virtual Machine can have a single application running multiple threads, which is known as concurrency. Threads are what make the program run. Each thread has a different priority, and when the machine queue fills up, the threads are executed in the order of their priority.


About a threads life cycle?

A Thread has many states in its life cycle. 1. Active - When you create a new thread 2. Running - When you invoke the thread.start() method 3. Waiting - When it is waiting on user input or for some other thread 4. Terminated/Dead - Once it finishes execution.


Can you restart stopped thread in java?

No. Once a thread is stopped you cannot restart it.


What is the meaning of the thread of araidne?

the thread of life in Greek myth of the three sisters one makes the string one pulls the string and one cuts the string that is the cycle of life.


What is the use of thread in java?

Thread is a single sequential flow of control within program. Each flow of control may be thought of as a seperate lines of code(module) is called as thread.Actually thread is a predefined class in java. threads are used to handle Exceptions in java.


What are the two ways of spawning a thread in Java?

You can create a Thread in Java by using two ways. 1. Extending the Thread class public class Test extends Thread { ..... } 2. Implementing the Runnable Interface public class Test implements Runnable { ... }


What are the factors affecting product life cycle?

Factors that affects the life cycle of a product depends on the product in question. A car tire as an example of a product has its lice spam and this is determined through the pattern of its life cycle. Factors that affects the life cycle of a car tire basically are four, and they are- Pattern of the thread on the tire, depth of the thread on the tire, nature of the road on which the car is been driven on, and the style of driving the car. these are the chief factors responsible for your tires long or short life and they affect the product life cycle.


How you would achieve multithreading in java?

Java provides built-in support for multithreaded programming. A multithreaded program contains two or more parts that can run concurrently. Each part of such a program is called a thread, and each thread defines a separate path of execution.A multithreading is a specialized form of multitasking. Multitasking threads require less overhead than multitasking processes.We achieve multithreading in Java by following this steps...New: A new thread begins its life cycle in the new state. It remains in this state until the program starts the thread. It is also referred to as a born thread.Runnable: After a newly born thread is started, the thread becomes runnable. A thread in this state is considered to be executing its task.Waiting: Sometimes a thread transitions to the waiting state while the thread waits for another thread to perform a task. A thread transitions back to the runnable state only when another thread signals the waiting thread to continue executing.Timed waiting: A runnable thread can enter the timed waiting state for a specified interval of time. A thread in this state transitions back to the runnable state when that time interval expires or when the event it is waiting for occurs.Terminated: A runnable thread enters the terminated state when it completes its task or otherwise terminates.


What is inline thread in java?

You can start a thread "inline" without implementing Runnable or extending Thread class( new Thread() { public void run(){// do something} } ).start();


What is the default priority of background thread in java?

Medium priority