week 2 - Introduction to multithreading in java Flashcards

(3 cards)

1
Q

threads

A

threads:
a unit of execution thats responsible for handling a specific subtask for the process.
Threads share the same address space as the process that created them and the same heap but they do not share STACKS , registers and program counter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

2 ways to create threads

A

so essentially two ways to create threads

one we extend the thread class and we override the run method to achieve thread functionality

note : with this approach of thread calss new object created each time so no shared attributes -> cant lead to race conditions

another way to create threads is to
implement runnable interface
forced to override the run method now
we call the thread constructor and we can pass that implements runnable as a parameter to thread constructor
This is succeptible to race condidtions as private attributes will be shared so if we have multiple threads executing (reading and accessing) it will lead to lost updates due to unpredicatable execution order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

just read

A

Threads dont obey execution of order in program

due to premptive schedule - as processes get interrupted and os decideds what to schedule next

How well did you know this?
1
Not at all
2
3
4
5
Perfectly