Filters
Question type

Study Flashcards

Which of the following scenarios may not always cause a deadlock among two threads? i.Thread one is in an infinite loop and has acquired a lock II.Both threads are in an infinite loop, and one thread has acquired a lock III.Both threads are in an infinite loop, and both threads have acquired locks


A) Only I
B) Only II
C) Only III
D) I, II, or III

E) A) and D)
F) A) and B)

Correct Answer

verifed

verified

Consider the following change to the deposit method in Section 22.4: Consider the following change to the deposit method in Section 22.4:   What is the consequence of this change?  A) The bank account balances may no longer be correctly updated. B) The printouts may become intermingled. C) The printouts may no longer display the correct balances. D) All of the above. What is the consequence of this change?


A) The bank account balances may no longer be correctly updated.
B) The printouts may become intermingled.
C) The printouts may no longer display the correct balances.
D) All of the above.

E) A) and B)
F) B) and C)

Correct Answer

verifed

verified

C

lock objects ensure that shared data are in a consistent state when several threads access them.What is a deadlock?


A) When multiple threads try to use the same shared data at the same time, and the threads become undone
B) When multiple threads copy the same shared data in order to proceed, consequently leaving the original lock object useless
C) When multiple threads intertwine multiple times and the lock object is lost, or unreachable
D) When multiple threads are not proceeding because they are currently waiting to acquire the same lock

E) A) and B)
F) B) and C)

Correct Answer

verifed

verified

For threads of equal priority, which is guaranteed by the thread scheduler that is part of the Java Virtual Machine? i.All will get time on the CPU II.All will get exactly equal time on the CPU III.The order threads run in the CPU will always be the same


A) Only I
B) Only II
C) I and III
D) II and III

E) C) and D)
F) B) and D)

Correct Answer

verifed

verified

Examine the SharedData class shown below.Suppose two threads are created so that each has access to the same SharedData object.Thread one calls setSharedData eight times with values 1...8 respectively, sleeping for 30 milliseconds between calls.Thread two calls getSharedData eight times, also sleeping for 30 milliseconds between calls.Which of the following orders of values is not possible for thread two to receive? Examine the SharedData class shown below.Suppose two threads are created so that each has access to the same SharedData object.Thread one calls setSharedData eight times with values 1...8 respectively, sleeping for 30 milliseconds between calls.Thread two calls getSharedData eight times, also sleeping for 30 milliseconds between calls.Which of the following orders of values is not possible for thread two to receive?    A) 1,2,3,4,5,6,7,8 B) 1,2,2,4,5,6,7,8 C) 1,2,3,4,5,6,8,8 D) 1,2,3,4,5,6,8,7


A) 1,2,3,4,5,6,7,8
B) 1,2,2,4,5,6,7,8
C) 1,2,3,4,5,6,8,8
D) 1,2,3,4,5,6,8,7

E) A) and B)
F) B) and C)

Correct Answer

verifed

verified

Assume two threads share a BankAccount object with balance of zero (0) , and that the BankAccount class provides deposit and withdraw methods as shown below.Thread one deposits $10 ten times and, concurrently, thread two withdraws $10 ten times.If the balance after all thread calls is 0, which statement is definitely true? Assume two threads share a BankAccount object with balance of zero (0) , and that the BankAccount class provides deposit and withdraw methods as shown below.Thread one deposits $10 ten times and, concurrently, thread two withdraws $10 ten times.If the balance after all thread calls is 0, which statement is definitely true?    A) The calls were interleaved: thread one, thread two, thread one, thread two, … B) The first call was to the deposit method. C) The last call was to the withdraw method. D) Each individual call to the deposit and withdraw methods ran to completion.


A) The calls were interleaved: thread one, thread two, thread one, thread two, …
B) The first call was to the deposit method.
C) The last call was to the withdraw method.
D) Each individual call to the deposit and withdraw methods ran to completion.

E) A) and C)
F) B) and D)

Correct Answer

verifed

verified

Why does the textbook recommend signallAll over the signal method?


A) The signalAll method is always more efficient
B) signal can lead to deadlocks when not every waiting thread is able to proceed
C) signalAll notifies the waiting threads that sufficient funds is absolutely available, while signal only notifies one at a time
D) None of the above

E) C) and D)
F) B) and C)

Correct Answer

verifed

verified

The ____ method is useful only if you know that a waiting thread can actually proceed.


A) run
B) signal
C) await
D) interrupted

E) None of the above
F) B) and D)

Correct Answer

verifed

verified

B

Class MyClass has a single ReentrantLock object, myLock.Suppose thread one calls myLock.lock() as it enters methodX and immediately completes its CPU time slice.What will happen as thread two calls methodY and attempts to call myLock.lock() ?


A) Thread two will wait for the lock.
B) Thread two will acquire the lock.
C) Deadlock will occur.
D) Thread two causes the IllegalStateMonitorException.

E) A) and D)
F) B) and D)

Correct Answer

verifed

verified

Which constructor can be used to create a new thread associated with a Runnable object?


A) public Thread(Runnable r)
B) public Thread()
C) public Runnable(Thread t)
D) public Thread(String s)

E) B) and D)
F) None of the above

Correct Answer

verifed

verified

Assume two threads share a BankAccount object with balance of zero (0) , and that the BankAccount class provides deposit and withdraw methods as shown below.Thread one deposits $10 ten times and, concurrently, thread two withdraws $10 ten times.Suppose a race condition occurs, and the race is finished first by thread one.What would you expect balance to be after all thread calls? Assume two threads share a BankAccount object with balance of zero (0) , and that the BankAccount class provides deposit and withdraw methods as shown below.Thread one deposits $10 ten times and, concurrently, thread two withdraws $10 ten times.Suppose a race condition occurs, and the race is finished first by thread one.What would you expect balance to be after all thread calls?    A) $10 B) $20 C) $0 D) a negative amount


A) $10
B) $20
C) $0
D) a negative amount

E) A) and B)
F) B) and C)

Correct Answer

verifed

verified

Which method do you call to make a thread ineligible to run on the CPU for a set number of milliseconds?


A) start
B) wait
C) await
D) sleep

E) All of the above
F) A) and B)

Correct Answer

verifed

verified

If you do not use the Runnable interface, what is necessary to create a new thread? i.Implement the Threadable interface II.Extend the Thread class and add a run() method to it III.Add a run method to any class


A) Only I
B) Only II
C) Only III
D) I and III

E) B) and C)
F) C) and D)

Correct Answer

verifed

verified

Assume three threads share a BankAccount object with a balance initially zero (0) , a ReentrantLock named myLock, and a condition object on myLock named insufficientFunds, as shown below.Thread one calls withdraw(30) , then thread two calls withdraw(20) and thread three calls deposit(45) .What is the balance after the three calls and after the waiting threads have had a chance to run? Assume three threads share a BankAccount object with a balance initially zero (0) , a ReentrantLock named myLock, and a condition object on myLock named insufficientFunds, as shown below.Thread one calls withdraw(30) , then thread two calls withdraw(20)  and thread three calls deposit(45) .What is the balance after the three calls and after the waiting threads have had a chance to run?    A) 0 B) 15 or 25 C) 45 D) -5


A) 0
B) 15 or 25
C) 45
D) -5

E) C) and D)
F) B) and D)

Correct Answer

verifed

verified

B

Which are ways that a thread can be blocked? i.when it is sleeping II.waiting for a lock to be available III.waiting after calling the await method


A) Only I
B) I and II
C) I and III
D) I, II, and III

E) A) and B)
F) None of the above

Correct Answer

verifed

verified

The ________ method stops the current thread for a given number of milliseconds.


A) run
B) await
C) sleep
D) delay

E) B) and D)
F) A) and B)

Correct Answer

verifed

verified

Which phrase best describes the purpose of a lock used in an object in one or more of its methods?


A) increased sharing
B) mutual exclusion
C) speed increase
D) privacy protection

E) A) and D)
F) A) and C)

Correct Answer

verifed

verified

What is the difference between calling the sleep method versus the await method?


A) sleep makes the current thread wait and allows another thread to acquire the lock object while the await pauses the current thread for a set time
B) await makes the current thread wait and allows another thread to acquire the lock object while the sleep pauses the current thread for a set time
C) sleep handles the current thread while the await handles the next thread
D) sleep and await are the same

E) A) and C)
F) B) and D)

Correct Answer

verifed

verified

Suppose run1 and run2 are objects of the class MyRunnable, which implements the Runnable interface.What is the result of the following calls? run1.run() ; run2.run() ;


A) run1 and run2 execute as independent threads.
B) Syntax error
C) Only run1 executes as an independent thread.
D) run1 and run2 run sequentially, not as independent threads.

E) A) and C)
F) None of the above

Correct Answer

verifed

verified

Which exception must be caught or declared when calling the sleep method?


A) IOException
B) IllegalStateMonitorException
C) InterruptedException
D) SleepException

E) B) and C)
F) B) and D)

Correct Answer

verifed

verified

Showing 1 - 20 of 81

Related Exams

Show Answer