📄 idgenerator.java
字号:
/* @LICENSE_COPYRIGHT@ */
package net.sf.irunninglog.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Class used to generate pseudo-unique id values. This class can be used to
* generate values that are unique within the currently running JVM. Values
* may be repeated after a server restart, etc. so these values should only be
* used to identify short-lived data.
*
* @author <a href="mailto:allan_e_lewis@yahoo.com">Allan Lewis</a>
* @version $Revision: 1.1.1.1 $ $Date: 2005/06/23 01:49:03 $
* @since iRunningLog 1.0
*/
public final class IdGenerator {
/** <code>Log</code> instance for this class. */
private static final Log LOG = LogFactory.getLog(IdGenerator.class);
/** Singleton instance. */
private static final IdGenerator INSTANCE;
/** The last id that was gegnerated. */
private long mLastId;
static {
INSTANCE = new IdGenerator();
}
/** Utility class - protect the default constructor. */
private IdGenerator() {
super();
mLastId = 0;
if (LOG.isDebugEnabled()) {
LOG.debug("Id generator has been successfully initialized");
}
}
/**
* Generate and return a new identifier. This method is guananteed to
* return a value that is unique <strong>within the life span of the
* currently </strong> running server. Values returned from this method
* are <strong>NOT</strong> guaranteed to be unique beyond that time frame.
*
* @return The generated identifier
*/
public static synchronized long generateId() {
long id = INSTANCE.mLastId;
if (LOG.isDebugEnabled()) {
LOG.debug("generateId: Generated an id of '" + id + "'");
}
INSTANCE.mLastId += 1;
return id;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -