0% found this document useful (0 votes)
11 views9 pages

Multithreading Introduction in Java by Deepak Smart Programming Lyst7480

The document provides an introduction to multithreading in Java, explaining multitasking, multiprocessing, and multithreading concepts. It outlines the differences between processes and threads, and describes how to create threads using the Thread class and Runnable interface. Additionally, it emphasizes that using the Runnable interface is preferable for thread creation due to Java's lack of support for multiple inheritance.

Uploaded by

Aakash Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views9 pages

Multithreading Introduction in Java by Deepak Smart Programming Lyst7480

The document provides an introduction to multithreading in Java, explaining multitasking, multiprocessing, and multithreading concepts. It outlines the differences between processes and threads, and describes how to create threads using the Thread class and Runnable interface. Additionally, it emphasizes that using the Runnable interface is preferable for thread creation due to Java's lack of support for multiple inheritance.

Uploaded by

Aakash Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Smart Programming : Channel

An investment in Knowledge pays the best interest….

Multithreading Introduction
in Java
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

=> Multitasking :-
 Performing multiple task at single time

 Examples :
o When we perform multiple task for example
opening vlc, word, notepad, browser on
single system etc

 Multitasking use the concept of context


switching internally

 Multitasking can be achieved by 2 ways :-


1. Process based multitasking (Multiprocessing)
2. Thread based multitasking (Multithreading)

 Multitasking is used to reduce the ideal time of


CPU.

1
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

=> Multiprocessing :-
 Multiprocessing is the part when one system is
connected with multiple processor (CPU)
 Multiprocessing is best suitable at system level
or OS level

=> Multithreading :-
 Multithreading is the part which which multiple
threads (sub-process) are executed at single
time
 Examples :
1. Word
2. VLC
3. Games
4. Animations
5. Browser
6. Web-servers
etc

2
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

 Multithreading is mostly implemented by java


itself, we have to implement less part of
multithreading.
 Java provides API for multithreading :-
1. Thread
2. Runnable
3. ThreadGroup
4. Concureency
5. ThreadPool
1. etc

3
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

=> What is difference between Process & Thread


?
1. Process is the heavy-weight task performing
multiple tasks
Thread is the light-weight sub-process
performing single task

2. Process does not depends on each other


Threads depends on each other

3. Context switching is difficult in process (takes


more time)
Context switching is easy in threads (takes less
time)

3. Process shares the different address space


Threads shares the same address space

4
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

4. Process does not require synchronization


Threads requires synchronization

=> How to create threads :


-> There are 2 ways to create threads :-
1. By using "Thread" class
2. By using "Runnable" interface

=> What is "Thread" :-


 Thread is the pre-defined class which is present
in java.lang package
5
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

 Syntax :
class Thread implements Runnable
{
//constructors

//methods
run()
start()
etc
}

=> What is "Runnable" :-


 Runnable is pre-defined interface present in
java.lang package

6
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

 Syntax :
interface Runnable
{
//method
run()
}

=> Which is better way to create thread, Thread


or Runnable ?
-> Runnable is better way to create threads in
java because if we inherit Thread class then we
were not able to inherit any other class as multiple
inheritance is not supported in java but if we inherit
Runnable interface then we can inherit more
interfaces and can inherit the class also

7
Smart Programming (Mohali, Chandigarh India)
Call or Whats App Online & Industrial Training: +91 62838-30308

Company Links & Contacts

Company Name: Smart Programming (+91 62838-30308)

Address : Chandigarh & Mohali (Punjab), India

Websites: https://www.smartprogramming.in/
https://courses.smartprogramming.in

Android App:
https://play.google.com/store/apps/details?id=com.sma
rtprogramming

YouTube Channel:
https://www.youtube.com/c/SmartProgramming

You might also like