long 类型的自增长ID生成类,支持多线程。

来源:互联网 发布:js windows调用firefox 编辑:程序博客网 时间:2024/06/03 02:20
/** * @author Geek_Soledad (66704238@51uc.com) */public interface IdGenerator<T> {   /**    * 生成下一个id并返回。    *     * @return 返回新的id.    */   public T next();

}

/** * long 类型的自增长ID生成类,支持多线程。 *  * @author msdx */public class IncreaseLongId implements IdGenerator<Long> {   private AtomicLong id;   protected IncreaseLongId() {      id = new AtomicLong();   }   public IncreaseLongId(long initialId) {      id = new AtomicLong(initialId);   }   @Override   public Long next() {      return id.incrementAndGet();   }}



0 0
原创粉丝点击