RequestMappingHandlerAdapter creates a new HandlerMethod for each request. HandlerMethods cache their MethodParameters to avoid costly reflection calls each time annotation stats are needed, but the per-request copy circumvents this cache. This patch explicitly copies the MethodParameter cache from a HandlerMethod and its request-scoped dependents.
Affects: 3.1.1, 3.1.2, 3.2 M2
#13936 monitor contention at org.springframework.core.MethodParameter.getParameterAnnotations() ("is duplicated by")
#17058 NPE in org.springframework.core.MethodParameter.getParameterName (possible race condition)
#17429 Thread contention in HandlerMethod due to unnecessary BeanFactory.getType call
This should now be resolved although using a slightly different approach. Here is the commit with the changes. It has also been applied to 3.1.x (and will be in 3.1.3) with a few other changes. Note however that currently there are (unrelated) build failures in both master and 3.1.x, so no snapshots are available yet.
Looks good... and incidentally, this fix might resolve a follow-on optimization that we noticed around ServletInvocableHandlerMethod. I'll try these out once a snapshot for 3.1.3 is available and see what the impact is. Thanks!