filmov
tv
Introduction to Multithreading in Java | Difference Between Multithreading And Multitasking

Показать описание
Subscribe The Channel
@technicalicode2261
concept covered :-
Introduction of Multithreading
Difference between Multithreading And Multitasking
Creating Threads
2 ways of creating Threads
Extending Thread Class
With a sample program
Introduction of Multithreading
Modern operating system has the capability to execute several program simultaneously i.e at the same time. This ability is known as multitasking. In system’s technology, it is called “Multithreading”.
Multithreading is a conceptual programming paradigm where a program is divided into two or more subprograms which can be implemented at the same time in parallel.
In most of our computer there is only on processor and hence, in reality the processor is doing only one thing at a time. However, the processor switches between the processes so fast that it appears to human being that all of them are being simultaneously.
Difference between Multithreading And Multitasking
Multithreading
It is a programming concept.
It supports execution of multiple parts of the same programs simultaneously.
The processor switches between different parts/threads of the program.
It is highly efficient
It helps in developing the efficient programs.
Multitasking
It is an operating system concept.
It supports execution of multiple tasks simultaneously.
The processor switches between multiple tasks
It is less efficient as compared to multithreading.
It helps in developing efficient OS
Creating Threads
For creating thread in java we create it in the form of objects that contain run() method. The run() method is the heart and soul of any thread. It makes the entire body of the thread. It makes the entire body of the thread. A run() looks like:
Public void run()
{
………
………
}
The run() is invoked by calling the start() method. Now remember this that if you want this run() method to behave like threaded program, you need to call the start() method. If you will call it by its name viz. run(), it is not going to show any multithreading property.
Now if we wan to create a thread, we can do it by two ways
By creating a thread class: for this you need to extend “Thread” class.
By converting a class to thread: for this you need to implement the “Runnable” interface.
Extending Thread Class
Declare the class as extending the Thread Class.
Implement the run() method.
Create a thread object and call the start() methods.
Class.
2. By converting a class to thread: for this you need to implement the Runnable Interface.
subscribe the channel
@technicalicode
#multithreading
#technicalicode
#multithreadinginjava
#multithread
@technicalicode2261
concept covered :-
Introduction of Multithreading
Difference between Multithreading And Multitasking
Creating Threads
2 ways of creating Threads
Extending Thread Class
With a sample program
Introduction of Multithreading
Modern operating system has the capability to execute several program simultaneously i.e at the same time. This ability is known as multitasking. In system’s technology, it is called “Multithreading”.
Multithreading is a conceptual programming paradigm where a program is divided into two or more subprograms which can be implemented at the same time in parallel.
In most of our computer there is only on processor and hence, in reality the processor is doing only one thing at a time. However, the processor switches between the processes so fast that it appears to human being that all of them are being simultaneously.
Difference between Multithreading And Multitasking
Multithreading
It is a programming concept.
It supports execution of multiple parts of the same programs simultaneously.
The processor switches between different parts/threads of the program.
It is highly efficient
It helps in developing the efficient programs.
Multitasking
It is an operating system concept.
It supports execution of multiple tasks simultaneously.
The processor switches between multiple tasks
It is less efficient as compared to multithreading.
It helps in developing efficient OS
Creating Threads
For creating thread in java we create it in the form of objects that contain run() method. The run() method is the heart and soul of any thread. It makes the entire body of the thread. It makes the entire body of the thread. A run() looks like:
Public void run()
{
………
………
}
The run() is invoked by calling the start() method. Now remember this that if you want this run() method to behave like threaded program, you need to call the start() method. If you will call it by its name viz. run(), it is not going to show any multithreading property.
Now if we wan to create a thread, we can do it by two ways
By creating a thread class: for this you need to extend “Thread” class.
By converting a class to thread: for this you need to implement the “Runnable” interface.
Extending Thread Class
Declare the class as extending the Thread Class.
Implement the run() method.
Create a thread object and call the start() methods.
Class.
2. By converting a class to thread: for this you need to implement the Runnable Interface.
subscribe the channel
@technicalicode
#multithreading
#technicalicode
#multithreadinginjava
#multithread