# Java: Thread Questions

Name _______________________________

1. Which areas of memory do separate threads share? Circle all that are correct.
   1. Call stack
   2. Heap
   3. Static memory
   4. They don't share any memory.
2. If cooperative multithreading is used, which of the following causes a thread to give up use of the CPU? Circle all that are correct.
   1. Expiration of its time-slice.
   2. Blocking by an IO request.
   3. A call to yield().
   4. Call to a synchronized method which is being executed by another thread.
   5. Call to a unsynchronized method which is being executed by another thread.
3. Which are correct statements about processes / tasks and threads? Circle all that are correct.
   1. Processes share the same virtual memory; threads do not.
   2. The communication cost is lower between threads than between processes.
   3. Multiple processes can only be run on CPUs with mulitple CPUs, but threads can be run even if there is one CPU.
   4. When you run several programs in your system (eg, a word processor, a browser, etc), they are started as separate threads (not processes).
4. Which are true statements about calling a GUI listener (eg, on a JButton). Circle all that are correct.
   1. Java starts a separate thread for each listener.
   2. Long calculations which are performed by a listener will block the GUI from responding to user actions.
   3. The user should start a separate thread for long CPU-intensive listener calculations.
   4. There is no need to create a separate thread for a long listener calculation if the calculation performs operations that frequently allow other threads to use the CPU.
5. Which classes can be used to create new threads? Circle all that are correct.
   1. Any class which is a subclass of Thread.
   2. Any class which implements the Runnable interface.
   3. Every class because every object has its own monitor.
6. In which situations are threads used or should be considered? Assume there is only one CPU on the machine the programming is running on. Circle all that are correct.
   1. CPU intensive operations which can be computed in parallel may be run on separate threads to improve performance.
   2. Multiple IO operations (eg, loading data from several network sources) can be performed in parallel by using separate threads to reduce the total wait time.
   3. Operations that require a timer.
   4. Long GUI calculations.
   5. Using large, slow (eg, O(N)), data structures.