问题描述
我有几个CMIS请求,需要并行执行。但是当我尝试(使用CompletableFutire或stream()。parallel()时,我得到了:
is
java.util.concurrent.ExecutionException: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A valid SecureContext was not provided in the RequestContext
我在做什么错? 以下代码是我尝试并行执行CMIS的尝试之一:
@Autowired
@Qualifier("searchService")
private org.alfresco.service.cmr.search.SearchService searchService;
....
searchService.query(searchParameters);
在串行执行中一切正常
解决方法
安全上下文绑定到主线程,并且不传播到子线程,您需要设置一个。 也许您可以尝试修改此代码段:
CompletableFuture.runAsync(() -> {
try {
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(userName);
// Do your stuff...
} finally {
AuthenticationUtil.popAuthentication();
}
});