Concurrency Flashcards
Performing two or more tasks at the same time
Multitasking
Two or more programs run in parallel (or
concurrently)
Multiprocessing
One program that performs two or more tasks
(threads) at the same time
In thread-based multitasking, multiple threads
(multiple parts of one program) run concurrently
Multithreading
a programming practice where more than one thread
runs within a program or process.
Multithreading
Types of Multitasking
Multiprocessing & Multithreading
Every running
application has at least one thread, the ______________.
main thread
T or F:
Threads share the process’ resources, including
memory and open files.
T
A thread that is started and waiting to be executed
Ready State
A thread is being executed
Running State
5 States of a Thread
Ready, Running, Suspended, Blocked, Terminated
Execution is paused and can be resumed where it left
off
Suspended
Thread is waiting for a request (I/O) to be completed or a resource cannot be accessed because it is being
used by another thread
Blocked
Execution is stopped and cannot be resumed
Terminated
Commonly Used Thread Methods
getName(), run(), sleep(), start(), join(), getPriority()
Thread method that Suspends the thread; enables you to specify the period the thread is suspended
sleep();
the entry point into the thread
run();
Waits for the thread to die/finish
join();
All implementing classes of runnable or those that extends the thread class must override this method.
run();
2 Ways to create a Thread
Extending Thread class;
Kart extends Thread;
Implementing Runnable
Kart extends Runnable
Thread myKart = new Thread(new Kart(constructor));
In Java, we use the _______________ keyword to lock a critical section.
synchronized
A major concern in multithreading is when two or more
threads share the same resource. Only one of them
should access the resource at one time to avoid ___________________________.
data
consistency errors
In Java, the keyword _________________ is used to limit the access (obtain lock) to a resource (object) to just one thread.
synchronized