In high volume (~50,000 requests per second) java web-app I'm using ThreadLocal to execute a task which should be executed per request scope.
I could achieve the same effect using Spring request scope and I wondered which is better performance wise?
In code, using ThreadLocal:
private static final ThreadLocal<SomeClass> myThreadLocal = new ThreadLocal<SomeClass>();
And for each http request setting:
myThreadLocal.set(new SomeClass());
Using Spring request scope:
@Component
@Scope("request")
public class SomeClass{
...
}
Now, what will cost more:
myThreadLocal.get();
OR
SpringContext.getBean(SomeClass.class);
I wonder if anyone has already tried such a benchmark?