Slide 1

Slide 1 text

Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.info o ffi ce: 14 -227 CSC 305 Individual Software Design and Development Lecture 08. Multithreading

Slide 2

Slide 2 text

De f inition • Concurrent or P a r a llel execution of t a sks • Improves perform a nce a nd responsiveness • Core concept in softw a re • Allows multiple t a sks to run concurrently within the s a me progr a m 2

Slide 3

Slide 3 text

Thread vs Process Process • Independent progr a m with its own memory sp a ce • H a s a m a in thre a d (the “m a in” method in J a v a ) Thre a d • Runs inside a process • Sh a res process memory/resources with other thre a ds An a logy: • Process = O ff ice building • Thre a d = Employees working in the s a me o ff ice 3

Slide 4

Slide 4 text

Java and Multithreading • Thre a d cl a ss • Runn a ble interf a ce 4

Slide 5

Slide 5 text

Example Without Multithreading

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Example With Multithreading

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Analogy 11

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Questions 13

Slide 14

Slide 14 text

Lab

Slide 15

Slide 15 text

Assignment 01 15

Slide 16

Slide 16 text

Assignment 01 • When click on Open, show a JFileChooser to select a folder. • Re a d a ll f ile n a mes from the folder a nd displ a y them in the JList or JTextAre a . • Use the f irst f ile in the list to: • Count lines → dr a w a box sized by line count. • Count if / switch / for / while → dr a w a nother box sized by complexity. • Comp a ring box sizes should show di ff erence. For example: 100 lines a nd 100 control st a tements → both boxes s a me size. • If f ile h a s @ a uthor a nd @version → dr a w h a ppy/serious f a ce. Otherwise → dr a w s a d f a ce. • Submit your code a nd your Cl a ss Di a gr a m 16

Slide 17

Slide 17 text

CSC 305 Individual Software Design and Development Javier Gonzalez-Sanchez, Ph.D. [email protected] Fall 2025 Copyright. These slides can only be used as study material for the class CSC305 at Cal Poly. They cannot be distributed or used for another purpose.