Ai
2 Star 3 Fork 1

汪少棠/java-se

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
PersonTest.java 2.55 KB
一键复制 编辑 原始数据 按行查看 历史
汪少棠 提交于 2023-07-08 10:49 +08:00 . 枚举创建单例
package org.example.enums;
import org.junit.Test;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/**
* 枚举创建单例
*
* @author wangMaoXiong
* @version 1.0
* @date 2023/7/8 10:18
*/
public class PersonTest {
/**
* 1147525854 Person{agencyCode='null', idenNo='null', idenType='null', perName='null', sexCode='null', control='null'}
* 1147525854 Person{agencyCode='null', idenNo='null', idenType='null', perName='null', sexCode='null', control='null'}
* 1147525854 Person{agencyCode='null', idenNo='null', idenType='null', perName='null', sexCode='null', control='null'}
* 1147525854 Person{agencyCode='null', idenNo='null', idenType='null', perName='null', sexCode='null', control='null'}
* 1147525854 Person{agencyCode='null', idenNo='null', idenType='null', perName='null', sexCode='null', control='null'}
* 1147525854 Person{agencyCode='null', idenNo='null', idenType='null', perName='null', sexCode='null', control='null'}
* 1147525854 Person{agencyCode='null', idenNo='null', idenType='null', perName='null', sexCode='null', control='null'}
* 1147525854 Person{agencyCode='null', idenNo='null', idenType='null', perName='null', sexCode='null', control='null'}
* 1147525854 Person{agencyCode='null', idenNo='null', idenType='null', perName='null', sexCode='null', control='null'}
* 1147525854 Person{agencyCode='null', idenNo='null', idenType='null', perName='null', sexCode='null', control='null'}
*
* @throws InterruptedException
*/
@Test
public void test1() throws InterruptedException {
int count = 10;
CountDownLatch countDownLatch = new CountDownLatch(count);
ExecutorService executorService = Executors.newCachedThreadPool();
for (int i = 0; i < count; i++) {
executorService.execute(new Runnable() {
@Override
public void run() {
Person person = Person.getInstance();
System.out.println(person.hashCode() + " " + person);
try {
TimeUnit.MILLISECONDS.sleep(1000 + new Random().nextInt(3000));
} catch (InterruptedException e) {
e.printStackTrace();
}
countDownLatch.countDown();
}
});
}
countDownLatch.await();
}
public static void main(String[] args) {
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/wangmx1993/java-se.git
git@gitee.com:wangmx1993/java-se.git
wangmx1993
java-se
java-se
master

搜索帮助