I'm trying to make my myFacadeProvider.get() return a thread specific MyFacade. This works whenever I'm in the normal WebApplication RequestContext since it returns the same MyFacade throughout the app. But if I create a new thread and do the myFacadeProvider.get() it will return the same MyFacade referenced in the WebApplication RequestContext instead of a new one for that specific thread. How can I make myFacadeProvider.get() return a thread specific MyFacade no matter what thread I'm in?
Some example code:
@Component
@Scope(value = WebapplicationContext.SCOPE_REQUEST)
public class MyFacade {
@Setter
private String work = "the main work";
public String doWork() {
return work;
}
}
@Component
public class QueryES {
@Autowired
private Provider<MyFacade> myFacadeProvider;
public void doThings() {
// This call gets a MyFacade that is thread safe in this scoped context and works as expected
MyFacade myFacade = myFacadeProvider.get();
myFacade.doWork(); // returns `the main work`
myFacade.setWork("the secondary work");
myFacade.doWork(); // returns `the secondary work`
// When I spin up a new thread and do the same call it will give me back the same myFacade
// that was returned previously instead of a new thread specific myFacade
Future<String> future = getFacadeAsyncDoWork(); // returns `the secondary work` instead of `the main work`
}
public ListenableFuture<String> getFacadeAsyncDoWork() {
return new AsyncResult<String>(doQueryWork());
}
public String doQueryWork() {
// Returns same myFacade as above, I want this to return a thread specific provider
MyFacade asyncMyFacade= myFacadeProvider.get();
return asyncMyFacade.doWork(); // returns `the secondary work` instead of `the main work`
}
}