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. Suppose thread two receives values 1, 2, 3, 4, 5, 6, 7, 8 respectively on its calls. Should we expect the same values for each program run? public class SharedData
{
Private int value;
Public void setSharedData(int n)
{
Value = n;
}
Public int getSharedData()
{
Return value;
}
}
A) Yes, because the sleep times are equal in between calls.
B) Yes, because that's the same order used by thread one to set the values.
C) No, because thread one may not set the data as 1,2,3,4,5,6,7,8 respectively.
D) No, because a race condition may result in a different order.
Correct Answer:
Verified
Q42: The _ method is useful only if
Q42: Assume two threads share a BankAccount object
Q43: a(n. _ object is used to control
Q48: Assume two threads share a BankAccount object
Q49: Assume two threads share a BankAccount object
Q50: A waiting thread is blocked until another
Q51: _ allow a thread to temporarily release
Q52: Consider the following change to the deposit
Q57: Which of the following statements is correct?
A)If
Q63: Calling the wait method in synchronized code
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents