CS2005 - Lecture 10 - Threads

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/10

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 2:58 PM on 11/18/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

11 Terms

1
New cards

Concurrency

Managing multiple tasks at the same time, but not necessarily doing them literally at the same instant

2
New cards

Parallelism

Doing multiple things at the exact same time, using multiple CPU cores

3
New cards

Can an application be concurrent but not parallel?

Yes e.g. multitasking on a single-core CPU

4
New cards

What is a thread?

A mini-program running inside a main program. Programs can have multiple threads doing tasks at the same time

5
New cards

Why use multithreading?

Responsiveness: Avoid blocking

Resource Sharing: Threads share memory by default

Economy: Faster to create/switch than processes

Scalability: Utilises multiple cores effectively

6
New cards

What are the states of a Java thread?

NEW: Created but not started

RUNNABLE: Ready or running (scheduler decides)

BLOCKED: Waiting for a monitor lock

WAITING: Indefinite wait

TIMED_WAITING: Waits with timeout

TERMINATED: Completed execution

7
New cards

What is Amdahl's Law?

Speedup <= 1/ S+[(1-S)/N], S=serial portion, N=cores. Limits speedup due to serial code

8
New cards

Name multicore programming challenges

Load balancing, Data dependencies/synchronisation, debugging parallel tasks

9
New cards

Why use multithreading in servers?

Single-threaded: Poor responsiveness (one client at a time)

Process-per-request: Heavy overhead

Multithreaded: Efficiently handle multiple requests (one thread per request)

10
New cards

Creating Threads in Java, Method 1: Extend Thread class

class MyTask extends Thread { public void run() { System.out.println("Task is running!"); } } public class Main { public static void main(String[] args) { MyTask t = new MyTask(); t.start(); } }

11
New cards

Creating Threads in Java, Method 2: Implement Runnable

class MyTask implements Runnable { public void run() { System.out.println("Task is running"); } } public class Main { public static void main(String[] args) { Threads t = new Thread(new MyTask()); t.start(); } }