until the event-dispatching thread has executed the specified code.
d. GUI event handling is executed in the event dispatcher thread.
#
Section 32.8 Thread Pools
18. Suppose there are three Runnable tasks, task1, task2, task3. How do you run them in a thread pool with 2 fixed
threads?
a. new Thread(task1).start(); new Thread(task2).start(); new Thread(task3).start();
b. ExecutorService executor = Executors.newFixedThreadPool(3); executor.execute(task1); executor.execute(task2);
executor.execute(task3);
c. ExecutorService executor = Executors.newFixedThreadPool(2); executor.execute(task1); executor.execute(task2);
executor.execute(task3);
d. ExecutorService executor = Executors.newFixedThreadPool(1); executor.execute(task1); executor.execute(task2);
executor.execute(task3);
#
19. How do you create a cached thread pool?
a. ExecutorService executor = Executors.newCachedThreadPool();
b. ExecutorService executor = Executors.newCachedThreadPool(1);
c. ExecutorService executor = Executors.newCachedThreadPool(2);
d. ExecutorService executor = Executors.newCachedThreadPool(3);
#
Section 32.9 Thread Synchronization
20. The keyword to synchronize methods in Java is .
a. synchronize
b. synchronizing
c. synchronized
d. Synchronized
#
21. Which of the following statements are true?
a. A synchronized instance method acquires a lock on the object for which the method was invoked.
b. A synchronized instance method acquires a lock on the class of the object for which the method was invoked.
c. A synchronized statement can be used to acquire a lock on any object, not just this object, when executing a block
of the code in a method.
d. A synchronized statement is placed inside a synchronized block.
#
Section 32.10 Synchronization Using Locks
22. Which of the following are correct statements to create a Lock?
a. Lock lock = new Lock();
b. Lock lock = new ReentrantLock();
c. Lock lock = new ReentrantLock(true);
d. Lock lock = new ReentrantLock(false);
#