复制代码代码如下:
teste de pacote;
importar java.util.concurrent.atomic.atomicinteger;
classe pública Idgereate {
Inteiro atômico final estático privado = new AtomicInteger (0);
public static long getid () {
longo tempo = system.currenttimemillis ();
StringBuilder str = new StringBuilder (20);
str.Append (tempo);
int intvalue = Integer.getAndIncrement ();
if (Integer.get ()> = 10000) {
Integer.set (0);
}
if (intvalue <10) {
str.Append ("000");
} else if (intvalue <100) {
str.Append ("00");
} else if (intvalue <1000) {
str.Append ("0");
}
str.Append (Intvalue);
return long.parselong (str.toString ());
}
public static void main (string [] args) {
for (int i = 0; i <100003; i ++) {
novo teste (). start ();
}
}
A classe estática privada teste estende o thread {
@Override
public void run () {
System.out.println (IDGEDER.GETID ());
}
}
}