package com.aionemu.chatserver.utils;
import java.util.BitSet;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
/**
* Simplified version of idfactory
*
* @author ATracer
*/
public class IdFactory {
private static final IdFactory instance = new IdFactory();
private final BitSet idList = new BitSet();
private final ReentrantLock lock = new ReentrantLock();
private final AtomicInteger nextMinId = new AtomicInteger(1);
public static IdFactory getInstance() {
return instance;
}
public int nextId() {
try {
lock.lock();
int nextId = idList.nextClearBit(nextMinId.intValue());
idList.set(nextId);
nextMinId.incrementAndGet();
return nextId;
} finally {
lock.unlock();
}
}
}
순위 | 닉네임 | 포인트 |
---|---|---|
1 |
![]() |
102,949 |
2 |
![]() |
63,733 |
3 |
![]() |
51,771 |
4 |
![]() |
36,923 |
5 |
![]() |
35,011 |
6 |
![]() |
29,470 |
7 |
![]() |
29,077 |
8 |
![]() |
28,199 |
9 |
![]() |
26,731 |
10 |
![]() |
17,020 |