INFO3136 EXAM Flashcards
What is a process?
The entire program
What is a thread?
Small part of a process
What is process based multi-tasking controlled by?
OS (Kernel)
What is thread based multi-tasking controlled by?
JVM
Each thread gets its own what? (2)
- Call Stack
- Program counter
What happens if a thread cannot complete its task in the allotted time?
The thread is suspended
What happens when a thread is suspended?
State data is stored in CPU cache memory until text turn
What are the 2 ways to create threads in Java?
- Implement Runnable interface
- Extend Thread class
What method is in the Runnable interface?
run()
Why should you never call the run() method?
Method is automatically invoked by JVM. If you call it explicitly then a new thread is never made
What method is used to signal to the JVM that a thread is ready?
start()
What method is used to give up a thread’s remaining time?
yield()
What method is used to temporarily stop a thread?
sleep(long milliseconds)
What kind of exception can the sleep() method throw?
InterruptedException
What is the normal priority of a thread?
5
What kind of scheduling involves threads of equal priorities?
round-robin scheduling
What is it called when a low-priority thread never gets to run due to higher priority threads?
thread contention or thread starvation
What is the concurrency problem encountered in the 70’s called?
Lost Update Scenario
What were created to fix concurrency issues?
Transaction Rules
What is an example of a synchronized data structure in Java?
Vector
What kind of data structure is an ArrayList when considering threads?
Unsynchronized
Which is faster, a synchronized data structure or an unsynchronized?
Unsynchronized
What is it called when an unsynchronized program component allows data corruption?
Race Condition
What is it called when a class or data structure does not allow data corruption?
Thread-safe
What is the portion of the program holding the variable or data structure that can cause race conditions?
Critical Region
What keyword is used to prevent multiple threads from affecting the critical region?
synchronized
What does the keyword synchronized do?
Gives the method a lock on the data structure to guarantee exclusive access
What state are threads placed in when waiting for a thread with a lock to finish processing?
wait
What 3 methods are part of the Lock interface?
- lock()
- unlock()
- newCondition()
What is meant by atomic in the atomic classes?
The whole operation is completed as a unit and cannot be interrupted
What is the keyword volatile attached to?
A Variable
What does the keyword volatile do?
Tells the JVM that the variable will be accessed by multiple threads, so the value should be read from main memory every time
Do volatile variables have locks on them?
No
What are the 5 states of a thread?
- new
- runnable/ready
- running
- blocked
- terminated/dead
What class holds the sleep() method?
Thread
If a thread is put to sleep with a lock on a data structure, what happens to the lock?
Nothing