49 lines
1.6 KiB
Java
49 lines
1.6 KiB
Java
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());
|
||
}
|
||
}
|