filmov
tv
Java Multithreading Thread and Runnable Tutorial
Показать описание
In this video tutorial, we will learn how to create threads in Java with examples.
Contents:
- Create a new thread by implementing Runnable interface at 5:05
- Create a new thread with Lambda implementing Runnable interface at 16:40
- Create a new thread by extending Thread class at 20:40
- A preferred way to create a thread at 28:30
#java #thread #multithreading
An application that creates an instance of Thread must provide the code that will run in that thread. Java provides two ways to create a thread programmatically.
1. Implementing the Runnable interface.
2. Extending the Thread class.
The life cycle of a Thread (Thread States):
A java thread can be in any of the following thread states during its life cycle i.e. New, Runnable, Blocked, Waiting, Timed Waiting or Terminated.
1) New
The thread is in the new state if you create an instance of Thread class but before the invocation of start() method.
2) Runnable
The thread is in the runnable state after the invocation of the start() method, but the thread scheduler has not selected it to be the running thread.
3) Running
The thread is in running state if the thread scheduler has selected it.
4) Non-Runnable (Blocked)
This is the state when the thread is still alive but is currently not eligible to run.
5) Terminated
A thread is in a terminated or dead state when its run() method exits.
Contents:
- Create a new thread by implementing Runnable interface at 5:05
- Create a new thread with Lambda implementing Runnable interface at 16:40
- Create a new thread by extending Thread class at 20:40
- A preferred way to create a thread at 28:30
#java #thread #multithreading
An application that creates an instance of Thread must provide the code that will run in that thread. Java provides two ways to create a thread programmatically.
1. Implementing the Runnable interface.
2. Extending the Thread class.
The life cycle of a Thread (Thread States):
A java thread can be in any of the following thread states during its life cycle i.e. New, Runnable, Blocked, Waiting, Timed Waiting or Terminated.
1) New
The thread is in the new state if you create an instance of Thread class but before the invocation of start() method.
2) Runnable
The thread is in the runnable state after the invocation of the start() method, but the thread scheduler has not selected it to be the running thread.
3) Running
The thread is in running state if the thread scheduler has selected it.
4) Non-Runnable (Blocked)
This is the state when the thread is still alive but is currently not eligible to run.
5) Terminated
A thread is in a terminated or dead state when its run() method exits.
Комментарии