Question

Simple java question

Consider the following statements related to AtomicIntegers compareAndSet(int expect, int update) method: LcompareAndSet set

Which of the following is not a condition that will temporarily suspend a threads execution: Select one: a. The threads tim

Consider the following statements related to AtomicInteger's compareAndSet(int expect, int update) method: LcompareAndSet sets the AtomicInteger's value to the given updated value, if its current value equals the expected value II. compareAndSet is a blocking call II. it is safe to call compareAndSet concurrently (from more than one thread) Which of the above statements are true? Select one a. All of I, I, and III b.Only I and III C. Only I and || d. None or only one of I, I, or III X e. Only l and II
Which of the following is not a condition that will temporarily suspend a thread's execution: Select one: a. The thread's time allotment has expired. b. The thread calls Thread.sleep(period) c. The thread callsThread.yield() d. A higher priority thread becomes available e. The thread enters a busy-waiting loop.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The answer for first question is b)Only I and III

compareAndSet method expects two parameters to be passes which are expected value and value to be expected. If the atomic integer value is equal to expected value, then it update the value of atomic integer with the value passed to be updated. compareAndSet method is a non-blocking call and can be run concurrently from different threads(more than one thread).

The answer for second question is a)the thread's time allotment has expired.

  • when Thread.sleep(period) is called, the thread will be put to sleep for a "period" of time.
  • when Thread.yield() is called, the thread gives a hint to the thread scheduler that it is ready to pause its execution. Then thread scheduler will check whether any higher priority thread is available.
  • When a higher priority thread becomes available, the thread will give way for higher priority thread to be executed.
  • When thread enters a busy waiting loop such as getting input from user, the thread will temporarily suspend its execution and keeps waiting for future action.
Add a comment
Know the answer?
Add Answer to:
Simple java question Consider the following statements related to AtomicInteger's compareAndSet(int expect, int up...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following program: # include <iostream> using namesapce std; void Func(int a, int bl double...

    Consider the following program: # include <iostream> using namesapce std; void Func(int a, int bl double number-25.0: int main) f int x-18, y-20; cout<c"Before: x- kex<" and y-eyecendl; Fundxy 1// end of main void Funcfint a, int b) int sum a+b; a-200; b-300; numberanumber+1.0 Which of the statements below are correct? (Select only the correct answers. There may be more than one) D A The statement double number-25.0; declares a global variable number B. The variables x and y are...

  • Consider the following statements concerning a positive integer : (i.) if n is a multiple of...

    Consider the following statements concerning a positive integer : (i.) if n is a multiple of 3, then n2 is a multiple of 3 [ii.) if n' is a multiple of 12, then n is a multiple of 12 (iii.) if nis a multiple of 6, then nis a multiple of 6 Which of the statements are true? Select one: O i. and iii. O All the statements None of the statements Only ii.

  • Which of the following statements concerning existing projects is true?An existing project should be: I. Continued...

    Which of the following statements concerning existing projects is true?An existing project should be: I. Continued when its continuing value is greater than both its liquidation and divestiture value. II. Liquidated when its liquidation value is greater than its divestiture value. III. Divested when its divestiture value is greater than both its continuing value and its liquidation value. Select one: a.  I only b. II only c. I and II only d.  I and III only e.  II and III only Which of...

  • Help with a Parallel and Distributed Programming assignment. In this assignment, you will be expl...

    Help with a Parallel and Distributed Programming assignment. In this assignment, you will be exploring different methods of counting the prime numbers between 1 and N. You will use 8 threads, and each will be given a range in which to count primes. The question is: where do you store your counter? Do you use a local variable? Do you use a global variable? Please use the following function to determine whether an integer number is a prime. // Return...

  • Which of the following statements regarding Bond equivalent yield (BEY) and discount yield is/are false: I....

    Which of the following statements regarding Bond equivalent yield (BEY) and discount yield is/are false: I. The discount yield is the return as a percentage of face value and the BEY is a return per dollar originally invested. II. A 365 day year is used on the discount yield and the BEY uses 360 days III. BEY is calculated the compounding effect while the discount yield is calculated without compounding Select one: a. II and III only b. II only...

  • QUESTION 1 Virtual Memory is a technique that makes excellent use of available space on a...

    QUESTION 1 Virtual Memory is a technique that makes excellent use of available space on a hard drive, to temporarily store data that would otherwise require massive amounts of main memory (RAM). True False 2 points    QUESTION 2 Which of these allocation schemes require the entire program to be loaded before execution can begin? I. Segmented/Demand paged II. Paged III. Segmented IV. Demand paged 2 points    QUESTION 3 Select the advantages of the First-In First-Out page replacement policy...

  • Multiple Choice Multiple Choice Section 4.1 Pointers and Dynamic Memory Consider the following statements: int *p;...

    Multiple Choice Multiple Choice Section 4.1 Pointers and Dynamic Memory Consider the following statements: int *p; int i; int k; i = 42; k = i; p = &i; After these statements, which of the following statements will change the value of i to 75? A. k = 75; B. *k = 75; C. p = 75; D. *p = 75; E. Two or more of the answers will change i to 75. Consider the following statements: int i =...

  • Use the following three statements to answer this question: I. When and we know the return...

    Use the following three statements to answer this question: I. When and we know the return on Security A, we can predict the return on Security B with certainty. II. Generally, security returns display positive correlations with one another but they are less than one, because all securities tend not to follow the movements of the overall market. III. Any value of correlation less than +1 provides a possibility of diversification. Select one: a. I is incorrect, II is correct,...

  • Need help writing Java code for this question. CircleFrame class is provided below. what happen after...

    Need help writing Java code for this question. CircleFrame class is provided below. what happen after u add the code and follow the requirement? It would be nice to be able to directly tell the model to go into wait mode in the same way that the model's notify method is called. (i.e. notify is called directly on the model, whereas wait is called indirectly through the suspended attribute.) Try altering the the actionPerformed method of the SliderListener innner class...

  • Some java questions: 18. Consider the following class definitions public class TestAB public static void main (String a...

    Some java questions: 18. Consider the following class definitions public class TestAB public static void main (String args) A bl new B() в ь2 -new B() ; b1.х, А.у, Ь2.х, в.у); System.out.printf ("%d, Sd, %d, d\n", class A public int x = 2; public static int y = 4; public A () ( X=y- class Bextends A public int x = 32; public static int y = 45; public B ( x ++y What is the result of attempting to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT