Ch 23 Review

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which of the following statements is false? a. If an operation requires the executing thread to hold a lock while the operation is performed, a thread must relase the lock before proceeding with the operation. Other threads attempting to perform an operation that requires the same lock will be blocked until the first thread releases the lock, at which point the blocked threads may attempt to acquire the lock and proceed with the operation. b. To specify that a thread must hold a monitor lock to execute a block of code, the code should be placed in a synchronized statement. c. Code in a synchronized statement is said to be guarded by the monitor lock; a thread must acquire the lock to execute the guarded statements. d. The monitor allows only one thread at a time to execute statements within synchronized statements that lock on the same object, as only one thread at a time can hold the monitor lock. The synchronized statements are declared using the synchronized keyword.

a. If an operation requires the executing thread to hold a lock while the operation is performed, a thread must release the lock before proceeding with the operation. Other threads attempting to perform an operation that requires the same lock will be blocked until the first thread releases the lock, at which point the blocked threads may attempt to acquire the lock and proceed with the operation. Actually, if an operation requires the executing thread to hold a lock while the operation is performed, a thread must acquire the lock before proceeding with the operation. Other threads attempting to perform an operation that requires the same lock will be blocked until the first thread releases the lock, at which point the blocked threads may attempt to acquire the lock and proceed with the operation.

Which of the following statements is false? a. Thread scheduling is platform independent. b. One simple thread-scheduler implementation keeps the highest-priority thread running at all times and, if there's more than one highest-priority thread, ensures that all such threads execute for a quantum each in round-robin fashion. c. The round-robin process for all highest-priority threads continues until all threads run to completion. d. Most programmers who use Java multithreading will not be concerned with setting and adjusting thread priorities

a. Thread scheduling is platform independent. Actually, thread scheduling is platform dependent-the behavior of a multithreaded program could vary across different Java implementations.

When using Java's built-in monitors, every object has a(n) ___ or a(n) ______ that the monitor ensures is held by a maximum of only one thread at any time. a. monitor lock, intrinsic lock b. built-in lock, free lock c. mutual exlcusion lock, synchronization lock d. None of the above.

a. monitor lock, intrinsic lock

The BlockingQueue interface declares which two methods for blocked adding and blocked removing of elements from a circular buffer? a. put and take. b. add and remove. c. push and pop. d. place and get.

a. put and take.

With timeslicing, each thread is given a limited amount of time, called a _____ to execute on a processor. a. quantum b. burst c. time allocation d. scheduling interval

a. quantum

A waiting thread transitions back to the ______ state only when another thread notifies it to continue executing. a. runnable b. terminated c. new d. blocked

a. runnable

The ArrayBlockingQueue method ______ returns the number of elements currently in the ArrayBlockingQueue? a. size. b. length. c. getSize. d. getLength.

a. size.

When a _____ method or block is running on an object, the object is locked so no other such method can run on that object at the same time. a. synchronized b. shared c. thread d. Writeable

a. synchronized

Which of the following statements is false? a. Java makes concurrency available to you through the language and APIS. b. Concurrency is a subset of parallelism. c. Today's multi-core computers have multiple processors that can perform tasks in parallel. d. Java programs can have multiple threads of execution, where each thread has its own method-call stack and program counter, allowing it to execute concurrently with other threads. This capability is called multithreading.

b. Concurrency is a subset of parallelism. Actually, parallelism is a subset of concurrency.

An ExecutorService object is created by calling a static method of which class? a. Executor. b. Executors. c. ExecutorService. d. Thread.

b. Executors.

Which of the following is not true of ExecutorService? a. It is a subinterface of Executor. b. It is an object that can be run in a separate thread. c. It declares method shutdown. d. It manages a group of threads.

b. It is an object that can be run in a separate thread.

Which of the following statements is false? a. A runnable thread can enter the timed waiting state for a specified interval of time. It transitions back to the runnable state when that time interval expires or when the event it's waiting for occurs. b. Timed waiting threads and waiting threads can use a processor, if one is available. c. A runnable thread can transition to the timed waiting state if it provides an optional wait interval when it's waiting for another thread to perform a task. Such a thread returns to the runnable state when it's notified by another thread or when the timed interval expires-whichever comes first. d. Another way to place a thread in the timed waiting state is to put a runnable thread to sleep-a sleeping thread remains in the timed waiting state for a designated period of time (called a sleep interval), after which it returns to the runnable state.

b. Timed waiting threads and waiting threads can use a processor, if one is available. Actually, timed waiting threads and waiting threads cannot use a processor, even if one is available.

Which of the following statements is false? a. Most operating systems support timeslicing, which enables threads of equal priority to share a processor. b. Without timeslicing, each thread in a set of equal-priority threads runs to completion before other threads of equal priority get a chance to execute. c. With timeslicing, even if a thread has not finished executing when its quantum expires, the processor is taken away from the thread and given to the next thread of equal priority, if one is available. d. An operating system's thread scheduler determines which thread runs next.

b. Without timeslicing, each thread in a set of equal-priority threads runs to completion before other threads of equal priority get a chance to execute. Actually, without timeslicing, each thread in a set of equal-priority threads runs to completion (unless it leaves the runnable state and enters the waiting or timed waiting state, or gets interrupted by a higher-priority thread) before other threads of equal priority get a chance to execute.

Two tasks that are operating ______ are both making progress at once. a.sequentially b.concurrently c.iteratively d.Recursively

b. concurrently

Two tasks that are operating ______ are executing simultaneously. a. concurrently b. in parallel c. sequentially d. iteratively

b. in parallel

The main method executes in the thread of execution. a. starting b. main с. lосal d. None of the above.

b. main

In a producer/consumer relationship, the ____ portion of an application generates data and stores it in a shared object, and the _______ portion of an application reads data from the shared object. a. consumer, producer b. producer, consumer c. outputter, inputter d. None of the above.

b. producer, consumer

Which of the following statements is false? a. A common way to perform synchronization is to use Java's built-in monitors. b. Every object has a monitor and a monitor lock (or intrinsic lock). c. A monitor ensures that its object's monitor lock is held by a maximum of two threads at a time. d. Monitors and monitor locks can be used to enforce mutual exclusion.

c. A monitor ensures that its object's monitor lock is held by a maximum of two threads at a time. Actually, a monitor ensures that its object's monitor lock is held by a maximum of only one thread at any time.

Which of the following statements is false? a. In a multithreaded application, threads can be distributed across multiple processors (if available) so that multiple tasks execute in parallel and the application can operate more efficiently. b. The JVM creates threads to run a program and for housekeeping tasks such as garbage collection. c. Multithreading can increase performance only on multi-core systems. d. The vast majority of programmers should use existing collection classes and interfaces from the concurrency APIS that manage synchronization for you.

c. Multithreading can increase performance only on multi-core systems. Actually, multithreading can also increase performance on single-processor systems-when one thread cannot proceed (because, for example, it's waiting for the result of an I/O operation), another can use the processor.

The preferred means of creating multithreaded Java applications is by implementing the _____ interface. An object of a class that implements this interface represents a task to perform. a. Thread b. Runner c. Runnable d. None of the above.

c. Runnable

In a producer/consumer relationship with a single cell of shared memory, which of the following is true? a. The consumer must run first. b. The producer must run first. c. The producer must run first or the consumer will have to wait. d. The consumer must run first or the producer will have to wait.

c. The producer must run first or the consumer will have to wait.

Interface ExecutorService provides the _______ method, which returns control to its caller either when all tasks executing in the ExecutorService complete or when the specified timeout elapses. a. waitForTermination b. wait c. awaitTermination d. None of the above.

c. awaitTermination

Another problem related to indefinite postponement is called _____. This occurs when a waiting thread (let's call this thread1) cannot proceed because it's waiting (either directly or indirectly) for another thread (let's call this thread2) to proceed, while simultaneously thread2 cannot proceed because it's waiting (either directly or indirectly) for thread1 to proceed. The two threads are waiting for each other, so the actions that would enable each thread to continue execution can never occur. a. impass b. standoff c. deadlock d. stalemate

c. deadlock

You can simulate atomicity by ensuring that __________. a. at least one thread carries out its operations on an object at a time b. two threads carry out their operations on an object in parallel c. only one thread carries out its operations on an object at a time d. None of the above.

c. only one thread carries out its operations on an object at a time

When a higher-priority thread enters the ready state, the operating system generally preempts the currently running thread (an operation known as preemptive scheduling). Depending on the operating system, a steady influx of higher-priority threads could postpone-possibly indefinitely-the execution of lower-priority threads. such indefinite postponement is sometimes referred to more colorfully as _________ a. fasting b. famine c. starvation d. malnourishment

c. starvation

A runnable thread enters the _____ state (sometimes called the dead state) when it successfully completes its task or otherwise terminates (perhaps due to an error). a. extinct b. defunct c. terminated d. aborted

c. terminated

Which of the following statements is false? a. A runnable thread transitions to the blocked state when it attempts to perform a task that cannot be completed immediately and it must temporarily wait until that task completes. b. When a thread issues an input/output request, the operating system blocks the thread from executing until that I/O request completes-at that point, the blocked thread transitions to the runnable state, so it can resume execution. C. A blocked thread cannot use a processor, even if one is available. d. Each of the above statements is true.

d. Each of the above statements is true.

It's recommended that you do not explicitly create and use Thread objects to implement concurrency, but rather use the _____ interface. a. ExecutorService b. Runnable c. Concurrent d. Executor

d. Executor

Which of the following statements is false? a. Thread synchronization is necessary only for shared mutable data, i.e., data that may change during its lifetime. b. With shared immutable data that will not change, it's not possible for a thread to see old or incorrect values as a result of another thread's manipulation of that data. c. When you share immutable data across threads, declare the corresponding data fields final to indicate that the values of the variables will not change after they're initialized. This prevents accidental modification of the shared data, which could compromise thread safety. d. Labeling object references as final indicates that the referenced object is immutable.

d. Labeling object references as final indicates that the referenced object is immutable. Actually, labeling object references as final indicates that the reference will not change, but it does not guarantee that the referenced object is immutable-this depends entirely on the object's properties.

Which of the following statements is false? a. Every Java thread has a thread priority that helps determine the order in which threads are scheduled. b. Each new thread inherits the priority of the thread that created it. c. Informally, higher-priority threads are more important to a program and should be allocated processor time before lower-priority threads. d. Thread priorities guarantee the order in which threads execute.

d. Thread priorities guarantee the order in which threads execute. Actually, even with thread priorities, the operating system determines the order in which threads execute.

Which of the following statements is false? a. If several synchronized statements in different threads are trying to execute on an object at the same time, only one of them may be active on the object-all the other threads attempting to enter a synchronized statement on the same object are placed in the blocked state. b. When a synchronized statement finishes executing, the object's monitor lock is released and one of the blocked threads attempting to enter a synchronized statement can be allowed to acquire the lock to proceed. c. Java also allows synchronized methods. Before executing, a synchronized instance method must acquire the lock on the object that's used to call the method. d. Using a synchronized block to enforce mutual exclusion is an example of the design pattern known as the Java Exclusion Pattern.

d. Using a synchronized block to enforce mutual exclusion is an example of the design pattern known as the Java Exclusions Pattern. Actually, using a synchronized block to enforce mutual exclusion is an example of the design pattern known as the Java Monitor Pattern.

Operating systems employ a technique called ________ to prevent indefinite postponement-as a thread waits in the ready state, the operating system gradually increases the thread's priority to ensure that the thread will eventually run. a. incrementing b. prioritizing c. maturing d. aging

d. aging

A new thread begins its life cycle by transitioning to the ____ state. a. runnable. b. waiting. c. terminated. d. new.

d. new


Set pelajaran terkait

Chapter 43: Loss, Grieving, and Death

View Set

Principles of Accounting Chapter 19

View Set

CompTIA A+ 220-1001 Printer Troubleshooting

View Set

AP2: Lab 6- Lymphatic and Immune System; Blood Typing

View Set