Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This method getNext must return a unique value nextValue
- public class Sequence {
- @GuardedBy("this") private int nextValue;
- public synchronized int getNext() {
- return nextValue++;
- }
- }
- Thread 1 gets value of nextValue, where nextValue = 5
- Thread 2 gets value of nextValue, where nextValue = 5
- public class Sequence {
- private int nextValue;
- public synchronized int getNext() {
- return nextValue++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement