Quiz 1
Explore key concepts of Java multithreading through quiz questions that examine differences between processes and threads, correct use of executor services, and thread behavior. Understand how tasks are represented by Runnable and Callable, thread execution order, and the impact of daemon threads on program execution.
We'll cover the following...
Question # 1
What are some of the differences between a process and a thread?
A process can have many threads, whereas a thread can belong to only one process.
A thread is lightweight than a process and uses less resources than a process.
A thread has some state private to itself but threads of a process can share the resources allocated to the process including memory address space.
Question # 2
Given the below code, can you identify what the coder missed?
void defectiveCode(final int n) throws ExecutionException, InterruptedException {
ExecutorService threadPool = Executors.newFixedThreadPool(5);
Callable<Void> sumTask = new