net.sf.jabb.util.thread
Class Sequencer

java.lang.Object
  extended by net.sf.jabb.util.thread.Sequencer
Direct Known Subclasses:
RangedSequencer

public class Sequencer
extends Object

It generates sequence of incremental numbers, ranging from 0 to Long.MAX_VALUE, without repeating or missing of any number.
生成序列数字,保证不重复渐增,范围从0到Long.MAX_VALUE,循环往复。

It is multi-thread safe, and has high performance.

它是线程安全的,而且性能高。

Author:
Zhengmao HU (James)

Field Summary
protected  AtomicLong currentValue
           
 
Constructor Summary
Sequencer()
          Constructs an instance that generates numbers starting from 0.
创建一个实例,且初始值为0。
Sequencer(long initialValue)
          Constructs an instance that generates numbers starting from specified value.
创建一个实例,且初始值为指定的值。
 
Method Summary
 long next()
          Gets the next number in sequence.
获得下一个序列值。
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentValue

protected AtomicLong currentValue
Constructor Detail

Sequencer

public Sequencer(long initialValue)
Constructs an instance that generates numbers starting from specified value.
创建一个实例,且初始值为指定的值。

Parameters:
initialValue - the first value that will be returned by next()

Sequencer

public Sequencer()
Constructs an instance that generates numbers starting from 0.
创建一个实例,且初始值为0。

Method Detail

next

public long next()
Gets the next number in sequence.
获得下一个序列值。

Returns:
the next number in sequence


Copyright © 2012. All Rights Reserved.