How can we use AtomicInteger for limited sequence generation say the sequence number has to be between 1 to 60. Once the sequece reaches 60 it has to start again from 1. I wrote this code though not quite sure wether this is thread safe or not?
public int getNextValue()
{
int v;
do
{
v = val.get();
if ( v == 60)
{
val.set(1);
}
}
while (!val.compareAndSet(v , v + 1));
return v + 1;
}