Final Exam Flashcards
(123 cards)
Process
Instance of an application running on a system
A process that tries to use memory not allocated to it will generate a ___
Segmentation fault
Each process can run one or more ___
Threads
T/F: Cores can run multiple threads at once
False
Each process is given a ___ to complete its work
Time slice (normally a constant)
T/F: Two processes cannot read from each other’s memory
True
All threads in the same process ___
Share the same memory space
The two ways to have Java execute threads
Executing the main thread
Extending the Thread class
T/F: A thread initiated with the start method will execute separately from the main method
True
Calling the run method instead of the start method on a thread
Will execute it in the main thread instead of its own
Scheduler
Controls when, and if, a thread gets to run. Minimal control over it. Like a black box–unpredictable.
NEW (thread state)
A thread has been created but start not called
RUNNABLE (thread state)
Start called and nothing is preventing thread from running
Running (unofficial thread state)
Thread is executing on a processor
DEAD (thread state)
A thread has finished its execution or has been terminated
To check if a thread is not DEAD state
isAlive()
Threads can be created by ___ Thread or ___ Runnable
Extending. Implementing. Runnable instances must be passed into thread constructors
Pros and cons of extending Thread
Pro:
Less code
Con:
Single inheritance. Run method optional. Can’t be restarted.
Pros and cons of implementing Runnable
Pros:
Multiple inheritance. Must override run. Can be restarted in new thread.
Cons:
More code
When multiple threads are running their output is ___
Interleaved. Some may run on same core, others on other cores.
Busy Wait
Pinging a thread repeatedly to see if it is complete (using isAlive()). Wastes CPU cycles while doing no work.
Threads can relinquish their time in a processor by using ___
Sleep
Sleep can be used to:
Simulate passage of time.
Let other processes work while it waits.
T/F: Upon awaking, a thread will immediately begin running again
False. It must wait to be scheduled.