SlideShare a Scribd company logo
M.SANDHIYA (MSC INFO TECH)
NADAR SARASWATHI COLLEGE OF ARTS
AND SCIENCE.
 Thread: single sequential flow of control
within a program
 Single-threaded program can handle one task
at any time.
 Multitasking allows single processor to run
several concurrent threads.
 Most modern operating systems support
multitasking.
 Reactive systems – constantly monitoring
 More responsive to user input – GUI application
can interrupt a time-consuming task
 Server can handle multiple clients simultaneously
 Can take advantage of parallel processing
 Different processes do not share memory space.
 A thread can execute concurrently with other
threads within a single process.
 All threads managed by the JVM share memory
space and can communicate with each other.
Creating threads in Java:
 Extend java.lang.Thread class
◦ run() method must be overridden (similar to main
method of sequential program)
◦ run() is called when execution of the thread begins
◦ A thread terminates when run() returns
◦ start() method invokes run()
◦ Calling run() does not create a new thread
 Implement java.lang.Runnable interface
Creating threads in Java:
 Extend java.lang.Thread class
 Implement java.lang.Runnable interface
◦ If already inheriting another class (i.e., JApplet)
◦ Single method: public void run()
◦ Thread class implements Runnable
isAlive()
 method used to find out the state of a thread.
 returns true: thread is in the Ready, Blocked, or
Running state
 returns false: thread is new and has not started or
if it is finished.
interrupt()
f a thread is currently in the Ready or Running
state, its interrupted flag is set; if a thread is
currently blocked, it is awakened and enters the
Ready state, and an java.io.InterruptedException is
thrown.
The isInterrupt() method tests whether the thread is
interrupted.
• Each thread is assigned a default priority of
Thread.NORM_PRIORITY (constant of 5). You can
reset the priority using setPriority(int
priority).
• Some constants for priorities include
Thread.MIN_PRIORITY Thread.MAX_PRIORITY
Thread.NORM_PRIORITY
• By default, a thread has the priority level of the thread
that created it.
 Thread-based Multitasking (Multithreading)
 Threads share the same address space.
 A thread is lightweight.
 Cost of communication between the thread is
low.
 Multithreading is a Java feature that allows concurrent
execution of two or more parts of a program for
maximum utilization of CPU. Each part of such
program is called a thread. So, threads are light-
weight processes within a process.
Threads can be created by using two mechanisms :
1. Extending the Thread class
2. Implementing the Runnable Interface
Multithreading can be a
Multithreading can be a great
way to increase the performance
of some types of programs.
However, mulithreading is even
more challenging than
multitasking. The threads are
executing within the same
program and are hence reading
and writing the same memory
simultanously. This can result in
errors not seen in a
singlethreaded program. Some
of these errors may not be seen
on single CPU machines, because
two threads never really execute
"simultanously". Modern
computers, though, come with
multi core CPUs, and even with
multiple CPUs too.
 General concurrency and multithreading theory:
 Multithreading Benefits
 Multithreading Costs
 Concurrency Models
 Same-threading
 Concurrency vs. Parallelism
 The basics of Java concurrency:
 Creating and Starting Java Threads
 Race Conditions and Critical Sections
 Thread Safety and Shared Resources
 Thread Safety and Immutability
 Java Memory Model
 Java Synchronized Blocks
 Java Volatile Keyword
 Java ThreadLocal
 Java Thread Signaling

More Related Content

PPTX
PPTX
Networking threads
PPTX
Multithreading
PPT
Os Threads
PPTX
PPTX
Threads ppt
PDF
4 threads
PPTX
Thread management
Networking threads
Multithreading
Os Threads
Threads ppt
4 threads
Thread management

What's hot (20)

PPTX
PPTX
threading and multi threading in java
PPTX
Lecture 3 threads
PDF
Multithreading
PPTX
Introduction to Multithreading in Java
PPT
MULTITHREADING CONCEPT
PPT
Multithreading Presentation
PPTX
Multithreading
PDF
Processes and-threads
PPTX
Operating system 20 threads
PDF
Operating Systems 1 (7/12) - Threads
PPTX
Architecture of web servers
PDF
What is simultaneous multithreading
PPT
Scheduler Activations - Effective Kernel Support for the User-Level Managemen...
PPTX
Directory based cache coherence
PPTX
Cache coherence problem and its solutions
PPTX
Lecture 5 inter process communication
PPTX
Lecture4
PPT
Parallel processing extra
threading and multi threading in java
Lecture 3 threads
Multithreading
Introduction to Multithreading in Java
MULTITHREADING CONCEPT
Multithreading Presentation
Multithreading
Processes and-threads
Operating system 20 threads
Operating Systems 1 (7/12) - Threads
Architecture of web servers
What is simultaneous multithreading
Scheduler Activations - Effective Kernel Support for the User-Level Managemen...
Directory based cache coherence
Cache coherence problem and its solutions
Lecture 5 inter process communication
Lecture4
Parallel processing extra
Ad

Similar to Mulitthread (20)

PDF
Multi t hreading_14_10
PPTX
Module 4 - Part 4 - Multithreaded Programming.pptx
PDF
Unit 5 - Java Multihhhhhhhhhhhhhhhhhhhhaaaaaaaaaaaaaaaaathreading.pdf
PPTX
Multithreading in java
PDF
Unit-3 MULTITHREADING-2.pdf
PPTX
OOP with Java - Multithreading - Module-5.pptx
PPTX
Object-Oriented-Prog_MultiThreading.pptx
PDF
java programming concept multithreading multitasking.pdf
PPTX
multithreading,thread and processinjava-210302183809.pptx
PPTX
8.-OBJECT-ORIENTED-PROGRAMMING-USING-JAVA-Multithreading.pptx
PPTX
Multithreading in java
PPT
multithreading
PPT
Multithreading
 
PPT
PPT
PPTX
OOPS object oriented programming UNIT-4.pptx
PPTX
Internet Programming with Java
PPT
Java Multithreading
PPT
Java multithreading
Multi t hreading_14_10
Module 4 - Part 4 - Multithreaded Programming.pptx
Unit 5 - Java Multihhhhhhhhhhhhhhhhhhhhaaaaaaaaaaaaaaaaathreading.pdf
Multithreading in java
Unit-3 MULTITHREADING-2.pdf
OOP with Java - Multithreading - Module-5.pptx
Object-Oriented-Prog_MultiThreading.pptx
java programming concept multithreading multitasking.pdf
multithreading,thread and processinjava-210302183809.pptx
8.-OBJECT-ORIENTED-PROGRAMMING-USING-JAVA-Multithreading.pptx
Multithreading in java
multithreading
Multithreading
 
OOPS object oriented programming UNIT-4.pptx
Internet Programming with Java
Java Multithreading
Java multithreading
Ad

Recently uploaded (20)

PDF
How Old Radio Shows in the 1940s and 1950s Helped Ella Fitzgerald Grow.pdf
PPTX
Hacking Movie – Best Films on Cybercrime & Digital Intrigue
PDF
TAIPANQQ SITUS MUDAH MENANG DAN MUDAH MAXWIN SEGERA DAFTAR DI TAIPANQQ DAN RA...
PDF
What is Rotoscoping Best Software for Rotoscoping in 2025.pdf
PDF
Between the Reels and the Revolution Enzo Zelocchi’s Unscripted Path Through ...
PPTX
What Makes an Entertainment App Addictive?
PPT
business model and some other things that
PPTX
shbthd htsh htrw hw htr 5w h5e 54 y.pptx
PDF
MAGNET STORY- Coaster Sequence (Rough Version 2).pdf
PPTX
SPARSH-SVNITs-Annual-Cultural-Fest presentation for orientation
PPTX
The story of Nomuzi and the way she was living
PPTX
Safety_Pharmacology_Tier2_Edibbbbbbbbbbbbbbbable.pptx
PPTX
just letters randomized coz i need to up
PDF
Ct.pdffffffffffffffffffffffffffffffffffff
PPTX
genderandsexuality.pptxjjjjjjjjjjjjjjjjjjjj
DOC
NSCAD毕业证学历认证,温哥华岛大学毕业证国外证书制作申请
PPTX
providenetworksystemadministration.pptxhnnhgcbdjckk
PDF
Rakshabandhan – Celebrating the Bond of Siblings - by Meenakshi Khakat
PDF
Download FL Studio Crack Latest version 2025
PDF
Keanu Reeves Beyond the Legendary Hollywood Movie Star.pdf
How Old Radio Shows in the 1940s and 1950s Helped Ella Fitzgerald Grow.pdf
Hacking Movie – Best Films on Cybercrime & Digital Intrigue
TAIPANQQ SITUS MUDAH MENANG DAN MUDAH MAXWIN SEGERA DAFTAR DI TAIPANQQ DAN RA...
What is Rotoscoping Best Software for Rotoscoping in 2025.pdf
Between the Reels and the Revolution Enzo Zelocchi’s Unscripted Path Through ...
What Makes an Entertainment App Addictive?
business model and some other things that
shbthd htsh htrw hw htr 5w h5e 54 y.pptx
MAGNET STORY- Coaster Sequence (Rough Version 2).pdf
SPARSH-SVNITs-Annual-Cultural-Fest presentation for orientation
The story of Nomuzi and the way she was living
Safety_Pharmacology_Tier2_Edibbbbbbbbbbbbbbbable.pptx
just letters randomized coz i need to up
Ct.pdffffffffffffffffffffffffffffffffffff
genderandsexuality.pptxjjjjjjjjjjjjjjjjjjjj
NSCAD毕业证学历认证,温哥华岛大学毕业证国外证书制作申请
providenetworksystemadministration.pptxhnnhgcbdjckk
Rakshabandhan – Celebrating the Bond of Siblings - by Meenakshi Khakat
Download FL Studio Crack Latest version 2025
Keanu Reeves Beyond the Legendary Hollywood Movie Star.pdf

Mulitthread

  • 1. M.SANDHIYA (MSC INFO TECH) NADAR SARASWATHI COLLEGE OF ARTS AND SCIENCE.
  • 2.  Thread: single sequential flow of control within a program  Single-threaded program can handle one task at any time.  Multitasking allows single processor to run several concurrent threads.  Most modern operating systems support multitasking.
  • 3.  Reactive systems – constantly monitoring  More responsive to user input – GUI application can interrupt a time-consuming task  Server can handle multiple clients simultaneously  Can take advantage of parallel processing  Different processes do not share memory space.  A thread can execute concurrently with other threads within a single process.  All threads managed by the JVM share memory space and can communicate with each other.
  • 4. Creating threads in Java:  Extend java.lang.Thread class ◦ run() method must be overridden (similar to main method of sequential program) ◦ run() is called when execution of the thread begins ◦ A thread terminates when run() returns ◦ start() method invokes run() ◦ Calling run() does not create a new thread  Implement java.lang.Runnable interface
  • 5. Creating threads in Java:  Extend java.lang.Thread class  Implement java.lang.Runnable interface ◦ If already inheriting another class (i.e., JApplet) ◦ Single method: public void run() ◦ Thread class implements Runnable
  • 6. isAlive()  method used to find out the state of a thread.  returns true: thread is in the Ready, Blocked, or Running state  returns false: thread is new and has not started or if it is finished. interrupt() f a thread is currently in the Ready or Running state, its interrupted flag is set; if a thread is currently blocked, it is awakened and enters the Ready state, and an java.io.InterruptedException is thrown. The isInterrupt() method tests whether the thread is interrupted.
  • 7. • Each thread is assigned a default priority of Thread.NORM_PRIORITY (constant of 5). You can reset the priority using setPriority(int priority). • Some constants for priorities include Thread.MIN_PRIORITY Thread.MAX_PRIORITY Thread.NORM_PRIORITY • By default, a thread has the priority level of the thread that created it.
  • 8.  Thread-based Multitasking (Multithreading)  Threads share the same address space.  A thread is lightweight.  Cost of communication between the thread is low.
  • 9.  Multithreading is a Java feature that allows concurrent execution of two or more parts of a program for maximum utilization of CPU. Each part of such program is called a thread. So, threads are light- weight processes within a process. Threads can be created by using two mechanisms : 1. Extending the Thread class 2. Implementing the Runnable Interface
  • 10. Multithreading can be a Multithreading can be a great way to increase the performance of some types of programs. However, mulithreading is even more challenging than multitasking. The threads are executing within the same program and are hence reading and writing the same memory simultanously. This can result in errors not seen in a singlethreaded program. Some of these errors may not be seen on single CPU machines, because two threads never really execute "simultanously". Modern computers, though, come with multi core CPUs, and even with multiple CPUs too.
  • 11.  General concurrency and multithreading theory:  Multithreading Benefits  Multithreading Costs  Concurrency Models  Same-threading  Concurrency vs. Parallelism  The basics of Java concurrency:  Creating and Starting Java Threads  Race Conditions and Critical Sections  Thread Safety and Shared Resources  Thread Safety and Immutability  Java Memory Model  Java Synchronized Blocks  Java Volatile Keyword  Java ThreadLocal  Java Thread Signaling