Skip to content

Commit 1eea9f6

Browse files
committed
Use ThreadLocal.withInitial to init ThreadLocal
1 parent 54b4fa5 commit 1eea9f6

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/main/java/org/apache/ibatis/executor/ErrorContext.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
public class ErrorContext {
2222

2323
private static final String LINE_SEPARATOR = System.lineSeparator();
24-
private static final ThreadLocal<ErrorContext> LOCAL = new ThreadLocal<>();
24+
private static final ThreadLocal<ErrorContext> LOCAL = ThreadLocal.withInitial(ErrorContext::new);
2525

2626
private ErrorContext stored;
2727
private String resource;
@@ -35,12 +35,7 @@ private ErrorContext() {
3535
}
3636

3737
public static ErrorContext instance() {
38-
ErrorContext context = LOCAL.get();
39-
if (context == null) {
40-
context = new ErrorContext();
41-
LOCAL.set(context);
42-
}
43-
return context;
38+
return LOCAL.get();
4439
}
4540

4641
public ErrorContext store() {

0 commit comments

Comments
 (0)