Exam 20: Multithreading

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

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

(Multiple Choice)
4.8/5
(32)

What is likely to be true when thread one is downloading a 1MB file while thread two is downloading another 1MB file?

(Multiple Choice)
4.9/5
(33)

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

(Multiple Choice)
4.8/5
(32)

Exactly when does a thread finish in Java?

(Multiple Choice)
4.9/5
(43)

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 ten times with values 1...10 respectively, sleeping for a random number of milliseconds between calls. Thread two calls getSharedData eight times, also sleeping for a random number of milliseconds between calls. Which of the following could be the last two values received by thread two? Public class SharedData { Private int value; Public void setSharedData(int n) { Value = n; } Public int getSharedData() { Return value; } }

(Multiple Choice)
4.9/5
(40)

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

(Multiple Choice)
5.0/5
(40)

The Runnable interface includes which method(s)? I public void run(Runnable runnable) II public void run() III public void start()

(Multiple Choice)
4.9/5
(41)

"Livelock" occurs when one thread runs continuously, while another thread never does. Which of the following is sufficient to cause livelock? I Thread one is in an infinite loop II Thread one possesses a lock and does not unlock it, but thread two requires the lock III Thread one requires a lock, but thread two possesses the lock

(Multiple Choice)
4.9/5
(33)

When a sleeping thread is interrupted, a(n) ____________________ is generated.

(Multiple Choice)
4.8/5
(37)

Suppose that the class XYZ implements the interface Runnable. Which code creates a thread object and makes it available to the scheduler to be executed?

(Multiple Choice)
4.8/5
(36)

The thread that calls signalAll must own the lock that belongs to the condition object on which signalAll is called. Otherwise, a(n) _______ ________ is thrown.

(Multiple Choice)
4.7/5
(39)

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

(Multiple Choice)
4.8/5
(35)

Class MyClass has two ReentrantLock objects, myLock1 and myLock2. Suppose thread one acquires myLock1 as it enters methodX and immediately completes its CPU time slice. After thread two enters methodY, it acquires myLock2 and tries to acquire myLock1. When thread one resumes, it tries to acquire myLock2. What will happen next?

(Multiple Choice)
4.8/5
(38)

Assume three threads share a BankAccount object with balance of zero (0), a ReentrantLock named myLock, and a condition object on myLock named lowBalanceCondition, as shown below. Thread one calls withdraw(30), then thread two calls withdraw(20)and thread three calls deposit(45). If the starting balance is 0, what is the balance after the three calls? Public void deposit(int dollars) { MyLock.lock(); Int newBalance = balance + dollars; System.out.println("depositing"); Balance = newBalance; MyLock.unlock(); } Public void withdraw(int dollars) { MyLock.lock(); While (balance < dollars) { LowBalanceCondition.await(); } Int newBalance = balance - dollars; System.out.println("withdrawing"); Balance = newBalance; MyLock.unlock(); }

(Multiple Choice)
4.7/5
(48)

A(n) ____ uses a small number of threads to execute a large number of runnables.

(Multiple Choice)
4.8/5
(38)

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? Public class SharedData { Private int value; Public void setSharedData(int n) { Value = n; } Public int getSharedData() { Return value; } }

(Multiple Choice)
4.9/5
(34)

Each thread runs for a short amount of time, called a ____________________.

(Multiple Choice)
4.7/5
(34)

Insert the statement that would start the following thread. Thread firstThread = new Thread(myRunnable); ____________________

(Multiple Choice)
4.8/5
(37)

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

(Multiple Choice)
4.9/5
(32)

When a thread is interrupted, the most common response is to terminate the ____________ method.

(Multiple Choice)
4.9/5
(40)
Showing 41 - 60 of 82
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)