Skip to content

Commit

Permalink
Avoid calling in the same thread
Browse files Browse the repository at this point in the history
  • Loading branch information
HaojunRen committed Apr 27, 2021
1 parent 7381fd1 commit e8d2a47
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ public WrapCallable(Callable<T> callable) {

@Override
public T call() throws Exception {

//Avoid calling in the same thread.
// Avoid calling in the same thread
if (asyncContext.getOriginThread().equals(Thread.currentThread())) {
return callable.call();
}

//Call the original method and copy some objects held by ThreadLocal.
// Call the original method and copy some objects held by ThreadLocal
Object[] objects = asyncContext.getObjects();
ThreadLocalCopier.before(objects);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public static void before(Object object) {
if (null == asyncContext) {
return;
}
//Avoid calling in the same thread.

// Avoid calling in the same thread
if (asyncContext.getOriginThread().equals(Thread.currentThread())) {
return;
}
Expand All @@ -37,10 +38,12 @@ public static void after(Object object) {
if (null == asyncContext) {
return;
}
//Avoid calling in the same thread.

// Avoid calling in the same thread
if (asyncContext.getOriginThread().equals(Thread.currentThread())) {
return;
}

ThreadLocalCopier.after();
}
}
Expand Down

0 comments on commit e8d2a47

Please sign in to comment.