Quiz 3 Flashcards
What two methods may Java threads be created by?
- Extending Thread class
- Implementing the Runnable interface
What is the run() method? What does it implement?
What executes in a separate thread; Runnable
What is the parameter for creating a Thread object?
An object of a class that implements Runnable
What does invoking the start() method do?
- Allocates memory and initializes a new thread in the JVM
- Calls the run() method, causing the JVM to run the thread
What does the join() method in Java do?
Waits for the thread to finish executing before another continues
What exception can the join() method in Java throw?
InterruptedException
What is the purpose of the Executor interface?
Organizing thread creation and omitting the need for explicitly creating Thread objects and invoking its start() method, as well as providing a mechanism for communication between concurrent tasks
What is the parameter for the execute() method?
A Runnable object
What model is the Executor framework based on?
producer-consumer
What is the purpose of the Callable interface?
To allow Java threads to return results
What does the submit() method in the Callable interface do?
Returns a result as a “Future object”
Which Java thread interface separates the creation of threads from the results they produce, rather than waiting for a thread to terminate before retrieving results, so the parent only waits for the results to become available?
Callable
What are some advantages of thread pools?
- Faster to service a request since a new thread doesn’t have to be created
- Allows the number of threads in the application(s) to be bound to the size of the pool, preventing infinite threads
- Allows different strategies for running tasks since the tasks to be performed are separated from task creation
What process resources are shared amongst threads?
- Address space
- Global variables
- Open files
- Child processes
- Pending alarms
- Signals and signal handlers
- Accounting information
What are benefits of multithreaded programming?
- Responsiveness
- Resource sharing
- Economy
- Scalability
What is the difference between a concurrent multicore system and a parallel one?
Concurrent allows more than one task to make progress, parallel can perform more than one task simultaneously
What are some challenges with multithreaded programming?
- Identifying tasks
- Balance
- Data splitting
- Data dependency
- Testing & debugging
A formula that identifies potential performance gains from adding additional computing cores to an application that has both serial and parallel components
Amdhal’s law
_____ parallelism focuses on distributing subsets of the same data across multiple computing cores and performing the same operations on each core
Data
_____ parallelism involves distributing not data, but tasks (threads) across multiple computing cores
Task
What’s the difference between user threads and kernel threads?
User threads are managed without kernel support, kernel threads are managed directly by the OS
Model that maps many user-level threads to one kernel thread, entire process blocks if a thread makes a blocking system call
many to one
Model that maps each user thread to a kernel thread, can run when a thread makes a blocking system call
one to one
Model that multiplexes many user-level threads to a smaller or equal number of kernel threads that can run in parallel
many to many
Model that is a variation of the many to many model, allows a user-level thread to be bound to a kernel thread
two level
Providers a programmer with an API for creating and managing threads
thread library