复制代码代码如下:
test de package;
import java.util.concurrent.atomic.atomicInteger;
classe publique idgenerate {
entier d'atomicInteger final statique privé = nouveau atomicInteger (0);
public static long getID () {
longue durée = System.currentTimemillis ();
StringBuilder str = new StringBuilder (20);
str.append (temps);
int intValue = Integer.GetAndInCment ();
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);
Retour Long.Parselong (str.toString ());
}
public static void main (String [] args) {
pour (int i = 0; i <100003; i ++) {
nouveau test (). start ();
}
}
Le test de classe statique privée étend le thread {
@Outrepasser
public void run () {
System.out.println (idGenerate.getId ());
}
}
}