Skip to content

Commit a87f079

Browse files
committed
refactor: 优化
1 parent 62f468d commit a87f079

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

hsweb-core/src/main/java/org/hswebframework/web/recycler/RecyclerImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import java.util.function.Consumer;
1212
import java.util.function.Supplier;
1313

14-
class RecyclerImpl<T> extends FastThreadLocal<RecyclerImpl<T>.ThreadLocalRecyclable> implements Recycler<T> {
14+
class RecyclerImpl<T> extends FastThreadLocal<RecyclerImpl.ThreadLocalRecyclable<T>> implements Recycler<T> {
1515

1616
private final Supplier<T> factory;
1717
private final Consumer<T> rest;
@@ -37,20 +37,20 @@ public RecyclerImpl(int size, Supplier<T> factory, Consumer<T> rest) {
3737
}
3838

3939
@Override
40-
protected ThreadLocalRecyclable initialValue() throws Exception {
41-
return new ThreadLocalRecyclable(factory.get(), false);
40+
protected ThreadLocalRecyclable<T> initialValue() throws Exception {
41+
return new ThreadLocalRecyclable<T>(factory.get(), false);
4242
}
4343

4444
@Override
45-
protected void onRemoval(ThreadLocalRecyclable value) {
45+
protected void onRemoval(ThreadLocalRecyclable<T> value) {
4646
rest.accept(value.value);
4747
}
4848

4949
@Override
5050
public <A, A1, A2, A3, A4, R> R doWith(A arg0, A1 arg1, A2 arg2, A3 arg3, A4 arg4, Function6<T, A, A1, A2, A3, A4, R> call) {
5151
// 非阻塞线程里 优先使用ThreadLocal池
5252
if (Schedulers.isInNonBlockingThread()) {
53-
ThreadLocalRecyclable ref = this.get();
53+
ThreadLocalRecyclable<T> ref = this.get();
5454
// 使用中,回调里又执行了?
5555
if (!ref.using) {
5656
try {
@@ -87,7 +87,7 @@ public <A, A1, A2, A3, A4, R> R doWith(A arg0, A1 arg1, A2 arg2, A3 arg3, A4 arg
8787
public Recyclable<T> take(boolean synchronous) {
8888
// 同步的,尝试使用ThreadLocal
8989
if (synchronous && Schedulers.isInNonBlockingThread()) {
90-
ThreadLocalRecyclable ref = this.get();
90+
ThreadLocalRecyclable<T> ref = this.get();
9191
if (!ref.using) {
9292
ref.using = true;
9393
return ref;
@@ -139,7 +139,7 @@ public void recycle() {
139139
}
140140

141141
@AllArgsConstructor
142-
class ThreadLocalRecyclable implements Recyclable<T> {
142+
static class ThreadLocalRecyclable<T> implements Recyclable<T> {
143143
private T value;
144144
private boolean using;
145145

0 commit comments

Comments
 (0)