KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a single-instance class, implementing ExceptionMapper. It's not a static class, but it's a class for which I know only single instance is created (I checked - constructor is called only once). My class uses @Context HttpServletRequest , and I can clearly observe that when my ExceptionMapper.toResponse() method is called, the @Context 'request' parameter has a value which is relevant for a request where the exception is thrown. The doc says this is indeed by-design supported feature and that it's done by using "proxies". I wonder how exactly this is implemented - how a single instance can have different member variable values simultaneously? Thank you, AG P.S.: here's the test code: @Provider public class MyExceptionMapper implements ExceptionMapper<Exception> { public MyExceptionMapper() { System.out.println("CTOR!!"); } @Context HttpServletRequest req; public static boolean done = false; public Response toResponse(Exception ex) { if (!done) { done = true; Thread.sleep(10000); } System.out.println(req.getRequestURI()); return null; } } My REST handler method throws exception, so when I execute the following 2 requests "in parallel" (the sleep above makes sure first one is not finished when second one arrives and IMHO should modify the one-and-only 'req' field): - http://localhost/app/one - http://localhost/app/two my program prints: CTOR! http://localhost/app/one http://localhost/app/two
Tags (comma-separated)
Save Edits
Cancel