Advertisement
Guest User

Untitled

a guest
Aug 20th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. //This method getNext must return a unique value nextValue
  2.  
  3. public class Sequence {
  4. @GuardedBy("this") private int nextValue;
  5. public synchronized int getNext() {
  6. return nextValue++;
  7. }
  8. }
  9.  
  10. Thread 1 gets value of nextValue, where nextValue = 5
  11. Thread 2 gets value of nextValue, where nextValue = 5
  12.  
  13. public class Sequence {
  14. private int nextValue;
  15. public synchronized int getNext() {
  16. return nextValue++;
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement