Files
spring-seq/src/main/java/com/yanghuanglin/springseq/config/Startup.java
2022-02-10 11:27:42 +08:00

49 lines
1.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.yanghuanglin.springseq.config;
import com.yanghuanglin.seq.generator.Generator;
import com.yanghuanglin.seq.po.Sequences;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Component
public class Startup implements ApplicationRunner {
@Resource
private Generator generator;
@Override
public void run(ApplicationArguments args) {
//释放未锁定序列号
generator.release();
Set<String> set = new HashSet<>();
//开启多线程进行测试
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(50, 50, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(1000));
for (int i = 0; i < 200; i++) {
int finalI = i;
threadPoolExecutor.execute(() -> {
Sequences sequences = generator.generate("SNT", "MISSION");
String formattedSeq = generator.format(sequences.getSeq(), 5, "处〔#year#10801#seq#");
if(finalI %5==4)
System.out.println(3/0);
generator.lock(sequences);
set.add(formattedSeq);
System.out.println(formattedSeq);
});
}
threadPoolExecutor.shutdown();
while (true) {
if (threadPoolExecutor.isTerminated())
break;
}
System.out.println(set.size());
}
}