Although a single thread typically processes one request (speaking of tomcat, for sure), a thread can process several requests over time, but not until the end of the current request, unless you use include / forward alike.
I would highly recommend that you use the (setAttribute ()) attribute of the specified w / your bean request and use it for profiling. If you cannot provide a request to various methods ... well, you are stuck with ThreadLocal [this is not a bad solution].
Alternatively, you can publish the code as you install / uninstall threadLocal bean.
Keep in mind that you need some control over this bean (it will not be available outside of the request).
Edit: forgot to ask: do you use try / finally call doFilter (...)?
the code should be such that
installBean();
try{
chain.doFilter(req, resp);
}finally{
Bean b = deinstallBean();
useTheMetrics(b);
}
source
share