interactive java note - m06_un012_p01

12
Prog rammin g Lan guag e (JAV A) Unit 6.12 - Basics of Threading Presentation 1

Upload: ebby-kyle

Post on 06-Apr-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Interactive Java Note - M06_UN012_P01

8/3/2019 Interactive Java Note - M06_UN012_P01

http://slidepdf.com/reader/full/interactive-java-note-m06un012p01 1/12

Programming Language (JAVA)

Unit 6.12 - Basics of Threading

Presentation 1

Page 2: Interactive Java Note - M06_UN012_P01

8/3/2019 Interactive Java Note - M06_UN012_P01

http://slidepdf.com/reader/full/interactive-java-note-m06un012p01 2/12

Revision

1. Define an applet and explain its lifecycle.

2. State the differences between applet and

application?

3. Describe the use of graphic class.

Page 3: Interactive Java Note - M06_UN012_P01

8/3/2019 Interactive Java Note - M06_UN012_P01

http://slidepdf.com/reader/full/interactive-java-note-m06un012p01 3/12

Objectives 

At the end of this presentation, you will beable to

• Explain the need of multitasking

• Recognize the concurrent execution ofmultithreaded applications

• Describe the uses of threads

Page 4: Interactive Java Note - M06_UN012_P01

8/3/2019 Interactive Java Note - M06_UN012_P01

http://slidepdf.com/reader/full/interactive-java-note-m06un012p01 4/12

Thread  – Definition

Thread can be defined as single, sequentialflow of control within a program.

Page 5: Interactive Java Note - M06_UN012_P01

8/3/2019 Interactive Java Note - M06_UN012_P01

http://slidepdf.com/reader/full/interactive-java-note-m06un012p01 5/12

Thread  – Types

Are of two types

• Single thread

• Multiple threads

Page 6: Interactive Java Note - M06_UN012_P01

8/3/2019 Interactive Java Note - M06_UN012_P01

http://slidepdf.com/reader/full/interactive-java-note-m06un012p01 6/12

Single threaded Application

• A task or process that is made up of only onethread is single-thread.

• A program that supports single thread iscalled single threaded application. 

Page 7: Interactive Java Note - M06_UN012_P01

8/3/2019 Interactive Java Note - M06_UN012_P01

http://slidepdf.com/reader/full/interactive-java-note-m06un012p01 7/12

Multi-threaded Application

• A task or process that is made of more thanone thread is multiple threading.

• A program that supports more than onethread is multi-threaded application

Page 8: Interactive Java Note - M06_UN012_P01

8/3/2019 Interactive Java Note - M06_UN012_P01

http://slidepdf.com/reader/full/interactive-java-note-m06un012p01 8/12

Multi-tasking

• Is the ability of an operating system toexecute more than one program

simultaneously.

Page 9: Interactive Java Note - M06_UN012_P01

8/3/2019 Interactive Java Note - M06_UN012_P01

http://slidepdf.com/reader/full/interactive-java-note-m06un012p01 9/12

Difference Between Multitasking andMultithreading

S.No: Multitasking Multithreading

1. More than one program getsexecuted simultaneously.

More than one part of a programcalled threads is executedsimultaneously.

2. Multitasking is a timesharingprocess. CPU switches fromone program to anotherprogram so quickly tocomplete all the programs

simultaneously.

Multithreading is also a timesharingprocess. CPU switches from oneactivity to another activity within theprogram so quickly to complete allthe activities simultaneously.

3. Since each program occupiesdifferent memory location,Multitasking is called asheavyweight process

Multithreading is a light weightprocess because the activities/ threads share the same memoryspace.

Page 10: Interactive Java Note - M06_UN012_P01

8/3/2019 Interactive Java Note - M06_UN012_P01

http://slidepdf.com/reader/full/interactive-java-note-m06un012p01 10/12

Uses of Threads

• A program can be split into separate tasksand further into threads. This increases theeffective usage of CPU during execution.

• The popularity of threading increased withGraphical User Interfaces. Threading systemallowed the user to attain better performance

in a program.• The introduction of threads created an illusion

that the program's performance was faster.

Page 11: Interactive Java Note - M06_UN012_P01

8/3/2019 Interactive Java Note - M06_UN012_P01

http://slidepdf.com/reader/full/interactive-java-note-m06un012p01 11/12

Importance of Threads

• In a Java program, one thread need not waitfor another thread to complete. This is called

asynchronous behaviour of threads.• Java provides few techniques to handle the

asynchronous behaviour of threads.

• Minimise the CPU's idle time.

Page 12: Interactive Java Note - M06_UN012_P01

8/3/2019 Interactive Java Note - M06_UN012_P01

http://slidepdf.com/reader/full/interactive-java-note-m06un012p01 12/12

Summary 

In this presentation, you learnt the following

• Threads can be defined as single, sequential flow of

control within a program.• The two types of threads are single and multiple

threads

• A program that supports single thread is single

threaded application.

• A program that supports more than one thread ismulti-threaded application.

• Multi-Tasking is the ability of an operating system toexecute more than one program simultaneously.