【发布时间】:2019-02-22 21:45:23
【问题描述】:
我们使用多线程,需要每个子线程中调用线程的上下文。我们使用的是 Spring 4.3。
例如:
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
CompletableFuture.supplyAsync(() -> {
...
try {
// take the security context from the caller
SecurityContextHolder.getContext().setAuthentication(authentication);
doOperations()
这种方法适用于安全上下文。它从调用者线程(rest 端点)传递,并将其传递给每个创建的可完成未来。
在调用链中的给定类中,我有以下构造:
@Context
protected ProvisioningContext provisioningContext;
@Context
protected UriInfo uriInfo;
如何在新创建的线程中正确传递所有上下文?
ThreadContext.getContext() 之类的方法不起作用。
【问题讨论】:
标签: java multithreading jax-rs