Skip to content

Commit

Permalink
Update JetCacheExecutor.java and Update AbstractExternalCacheTest.java (
Browse files Browse the repository at this point in the history
#811)

* Update JetCacheExecutor.java

做了以下两点改动:
1.使用了AtomicInteger以确保threadCount的线程安全性
2.在创建新的线程时使用了getAndIncrement()方法来递增计数

* Update AbstractExternalCacheTest.java

修改assertNull()使用错误

* Update AbstractExternalCacheTest.java
  • Loading branch information
xiezheng-XD committed Aug 31, 2023
1 parent 9d816fc commit 0482d68
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Created on 2017/5/3.
Expand All @@ -14,7 +15,7 @@ public class JetCacheExecutor {
protected volatile static ScheduledExecutorService defaultExecutor;
protected volatile static ScheduledExecutorService heavyIOExecutor;

private static int threadCount;
private static AtomicInteger threadCount = new AtomicInteger(0);

static {
Runtime.getRuntime().addShutdownHook(new Thread() {
Expand Down Expand Up @@ -55,7 +56,7 @@ public static ScheduledExecutorService heavyIOExecutor() {
synchronized (JetCacheExecutor.class) {
if (heavyIOExecutor == null) {
ThreadFactory tf = r -> {
Thread t = new Thread(r, "JetCacheHeavyIOExecutor" + threadCount++);
Thread t = new Thread(r, "JetCacheHeavyIOExecutor" + threadCount.getAndIncrement());
t.setDaemon(true);
return t;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected void nullKeyConvertorTest() {
d2.setName("HL2");

cache.put(d1, "V2");
Assert.assertNull("V2", cache.get(d2));
Assert.assertNull(cache.get(d2));
Assert.assertNull(cache.get(d3));
}
}
Expand Down

0 comments on commit 0482d68

Please sign in to comment.