通过eclipse创建maven工程:
http://jingyan.baidu.com/article/2fb0ba40a2b22b00f2ec5faf.html
通过增加synchronized修饰来实现线程安全:
package com.yihong.javaThread;
import net.jcip.annotations.*;
@ThreadSafe
public class Sequence {
@GuardedBy(
"this")
private int nextValue;
public synchronized int getNext() {
return nextValue++;
}
}