Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class IdGetter {
- private AtomicLong curr;
- private AtomicReference<Queue<Long>> priorityQueue;
- public IdGetter(final long start) {
- priorityQueue = new AtomicReference<>(new PriorityQueue<>());
- curr = new AtomicLong(start);
- }
- public void remove(final long id) {
- if (id <= curr.get()) {
- priorityQueue.get().add(id);
- }
- }
- public long get() {
- if (!priorityQueue.get().isEmpty()) {
- return priorityQueue.get().poll();
- }
- return curr.getAndIncrement();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement