I need a class which creates Objects assigning an ID to each Object created. This ID is as usual an int attribute to the class. I want this value (ID) to be increased each t
I would suggest to use AtomicInteger, which is thread-safe
AtomicInteger
class MyObject { private static AtomicInteger uniqueId=new AtomicInteger(); private int id; MyObject() { id=uniqueId.getAndIncrement(); } }