Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Async method in new thread use AopContext.currentProxy() can not get proxy object(when expose-proxy=true) [SPR-10720] #15348

Closed
spring-issuemaster opened this issue Jul 3, 2013 · 1 comment

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Jul 3, 2013

zhangkaitao opened SPR-10720 and commented

modify org.springframework.aop.interceptor.AsyncExecutionInterceptor

from

Future<?> result = determineAsyncExecutor(specificMethod).submit(
          new Callable<Object>() {
                   public Object call() throws Exception {
                            try {
                                     Object result = invocation.proceed();
                                     if (result instanceof Future) {
                                              return ((Future<?>) result).get();
                                     }
                            }
                            catch (Throwable ex) {
                                     ReflectionUtils.rethrowException(ex);
                            }
                            return null;
                   }
          }); 

to


        final Method setCurrentProxyMethod = ReflectionUtils.findMethod(AopContext.class, "setCurrentProxy", Object.class);

        final Object currentProxy = AopContext.currentProxy();
        ReflectionUtils.makeAccessible(setCurrentProxyMethod);
        Future<?> result = determineAsyncExecutor(specificMethod).submit(
                new Callable<Object>() {
                    public Object call() throws Exception {
                        try {
                            if(currentProxy != null) {
                                ReflectionUtils.invokeMethod(setCurrentProxyMethod, null, currentProxy);
                            }
                            Object result = invocation.proceed();
                            if (result instanceof Future) {
                                return ((Future<?>) result).get();
                            }
                        }
                        catch (Throwable ex) {
                            ReflectionUtils.rethrowException(ex);
                        } finally {
                            if(currentProxy != null) {
                                ReflectionUtils.invokeMethod(setCurrentProxyMethod, null, (Object) null);
                            }
                        }
                        return null;
                    }
                });



Affects: 3.2.3

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jan 12, 2019

Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.