mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix dead lock bug
This commit is contained in:
@@ -3,6 +3,7 @@ package cn.hutool.core.lang;
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SingletonTest {
|
||||
@@ -27,4 +28,24 @@ public class SingletonTest {
|
||||
private String name;
|
||||
private String age;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试单例构建属性锁死问题
|
||||
* C构建单例时候,同时构建B,此时在SimpleCache中会有写锁竞争(写入C时获取了写锁,此时要写入B,也要获取写锁)
|
||||
*/
|
||||
@Test(timeout = 1000L)
|
||||
public void reentrantTest(){
|
||||
final C c = Singleton.get(C.class);
|
||||
Assert.assertEquals("aaa", c.getB().getA());
|
||||
}
|
||||
|
||||
@Data
|
||||
static class B{
|
||||
private String a = "aaa";
|
||||
}
|
||||
|
||||
@Data
|
||||
static class C{
|
||||
private B b = Singleton.get(B.class);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user