复制代码代码如下:
prueba de paquete;
import java.util.concurrent.atomic.atomicinteger;
clase pública IDGENERATE {
Integer de AtomicInteger final estático privado = nuevo AtomicInteger (0);
public static long getid () {
mucho tiempo = system.currentTimemillis ();
StringBuilder str = new StringBuilder (20);
str.append (tiempo);
int intValue = integer.getAndIncrement ();
if (integer.get ()> = 10000) {
entero.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) {
para (int i = 0; i <100003; i ++) {
nueva prueba (). Start ();
}
}
La prueba de clase estática privada extiende el hilo {
@Anular
public void run () {
System.out.println (idgenerate.getId ());
}
}
}