0

Explain Life cycle of thread?

Java, life cycle of thread...

28th Aug 2017, 3:09 PM
Sreejith P
Sreejith P - avatar
4 Respostas
+ 8
start is the initial state / method. run the state / method where the thread stays all time until it returns from there by a certain condition (you can check a bool variable in a loop for example), when it returns from run, the thread is stopped. Don't use the stop or suspend methods! They are not safe. For the other states / actions, see https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html You might check the methods wait() and interrupt() for your block action. As well as join() for synchronisation. Runnable is not a state, but an interface which is implemented by Thread. To customize your own Runnable or Thread, you can either implement Runnable or extend Thread. See the Oracle tutorials: https://docs.oracle.com/javase/tutorial/essential/concurrency/index.html
28th Aug 2017, 3:53 PM
Tashi N
Tashi N - avatar
+ 8
start() -> run() -> does whatever the thread needs to do -> return from run method. I don't know what exactly you want to know. Any particular questions?
28th Aug 2017, 3:42 PM
Tashi N
Tashi N - avatar
+ 2
@Tashi N I mean different states like running ,runnable ,block and dead of a thread
28th Aug 2017, 3:45 PM
Sreejith P
Sreejith P - avatar
+ 1
thank you
29th Aug 2017, 1:02 AM
Sreejith P
Sreejith P - avatar