0% found this document useful (0 votes)
8 views10 pages

Java Threads

The document provides an overview of Java threads, explaining their definition, advantages, disadvantages, and life cycle. It discusses concurrency problems that can arise when multiple threads interact with shared resources, such as race conditions and deadlocks. Additionally, it differentiates between asynchronous and synchronous execution of threads, highlighting the performance benefits of asynchronous programming.

Uploaded by

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

Java Threads

The document provides an overview of Java threads, explaining their definition, advantages, disadvantages, and life cycle. It discusses concurrency problems that can arise when multiple threads interact with shared resources, such as race conditions and deadlocks. Additionally, it differentiates between asynchronous and synchronous execution of threads, highlighting the performance benefits of asynchronous programming.

Uploaded by

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

Research: Java Threads

Lecturer:
Chhom Makara

Members:
Reasey Kunnvath
Sreng Phanith
Hem Ihong
Da Phadenphorakden
Contents
01 03 05
WHAT IS JAVA LIFE CYCLE OF ASYNCHRONOU
THREADS? THREADS S AND
SYNCHRONOUS

02 04
ADVANTAGES & WHAT IS
DISADVANTAGE CONCURRENCY
S OF THREADS PROBLEM?
1. What is Java Threads?
 A thread in Java is a path of execution
within program. Every Java program
has at least one main thread, created
by Java Virtual Machine (JVM)

 Threads in java allows program to


operate more efficiently by doing
multiple things at the same time.

 It can be used to perform any tasks in


the background without interrupting
the flows of MAIN program.
1. What is Java Threads?
 Two ways to create a thread is by using Extend Syntax and
Implement Syntax
 Extend Syntax

 Implement Syntax
Running Threads
Running Threads
2. Advantages & Disadvantage of
Threads
Advantages Disadvantages
 Improved performance  Increased debug complexity
 Responsiveness  Synchronization issues
 Resource utilization  Reduced performance on limited
 Simplified programming resources system
 Deadlock
3. Life Cycle of Thread
STATE:
 New: Thread was created but not yet started.
 Runnable: Thread is ready to run.
 Running: Thread is currently executing.
 Blocked: Thread is waiting for specific event to occur
(Synchronization, Input/Output).
 Waiting: Thread is waiting for another thread to perform a
specific action.
 Timed Waiting: Thread is waiting for a specific amount of time to elapse.
 Terminated: Thread has completed/terminated.
4. Concurrency Problem
 Concurrency problem occurs when multiple threads interacts with shared
resources that could lead to unexpected or incorrect result. These problems
include Race condition, Deadlocks, Livelocks and Starvation.

 Race condition: Two threads try to increase a shared counter at the same time leading
to incorrect result.
 Deadlocks: Each thread is waiting for resources that another thread is using.
 Livelocks: When threads are constantly trying to acquire resources but never succeed.
 Starvation: When a thread with lower priority is unable to progress due to a higher
priority thread.
5. Asynchronous vs Synchronous
 Asynchronous: Threads can be executed concurrently OR
executed at the same time.
 Synchronous: Threads are executed in orders OR wait for each
other.

Asynchronous programming often leads to better performance,


when dealing with tasks that might take a long time to complete.

You might also like