public class IdGenerator { private long maxId; public IdGenerator(long start) { maxId = start; } public long getNextId () { return ++maxId; } } // IdGenerator
".
There is in fact sometimes the need to supply different entities with unique ids. As I wrote, in THIS situation you will have to use a singleton, otherwise not.
You need to create an account or log in to post comments to this site.
public synchronized long getNextId () {
return ++maxId;
}
If one generator supplies the entire application with ids you will have to implement it as singleton.