可以参考下述代码:
private static int sn = 0;public synchronized int getNextSN() { return ++sn;}public int getCurrentSN() { return sn;}