Skip to content

Commit e5df1e8

Browse files
committed
修复DigestUtils在多线程下的问题
1 parent 26dc740 commit e5df1e8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.hswebframework.web.utils;
2+
3+
import lombok.SneakyThrows;
4+
import org.junit.Test;
5+
6+
import java.util.HashSet;
7+
import java.util.Set;
8+
import java.util.concurrent.ConcurrentHashMap;
9+
10+
import static org.junit.Assert.*;
11+
12+
public class DigestUtilsTest {
13+
14+
15+
@Test
16+
@SneakyThrows
17+
public void test() {
18+
Set<String> check = ConcurrentHashMap.newKeySet();
19+
20+
for (int i = 0; i < 1000; i++) {
21+
new Thread(() -> check.add(DigestUtils.md5Hex("test")))
22+
.start();
23+
}
24+
Thread.sleep(1000);
25+
System.out.println(check);
26+
assertEquals(1, check.size());
27+
}
28+
}

0 commit comments

Comments
 (0)