public class idgenerate {
private static final atomicinteger integer = new atomicinteger(0);
public static long getid() {
long time = system.currenttimemillis();
stringbuilder str = new stringbuilder(20);
str.append(time);
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++) {
new test().start();
}
}
private static class test extends thread {
@override
public void run() {
system.out.println(idgenerate.getid());
}
}
}
如对本文有疑问, 点击进行留言回复!!
解决idea中出现“illegal character U+200B” 问题
荐 为什么加了@Transactional注解,事务没有回滚?
Attribute ‘sklearn.linear_model._logistic.LogisticRegression.multi_class‘ must be explicitly set to
Java/Python实现 LeetCode剑指Offer 14-I.剪绳子(动态规划)
网友评论