<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=nikita.tovstoles" rel="nofollow">Nikita Tovstoles</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9298?redirect=false" rel="nofollow">SPR-9298</a></strong> and commented</p>
<p dir="auto">On each web request, RequestMappingHandlerAdapter.invokeHandlerMethod() indirectly calls MethodParameter.getParameterAnnotations(), which calls into JRE lib method causing monitor contention. See screen shots &amp; <a href="http://ecorebates-misc.s3.amazonaws.com/CLP-895/clp-895-init.snapshot" rel="nofollow">YourKit snapshot</a>. Most likely will need to patch spring (caching results of calls to java.lang.reflect.Method.getParameterAnnotations())</p>
<p dir="auto">Looking at Spring's MethodParameter:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="public Annotation[] getParameterAnnotations() {
     if (this.parameterAnnotations == null) {
          Annotation[][] annotationArray = (this.method != null ?
                        this.method.getParameterAnnotations() : this.constructor.getParameterAnnotations());
          if (this.parameterIndex &gt;= 0 &amp;&amp; this.parameterIndex &lt; annotationArray.length) {
               this.parameterAnnotations = annotationArray[this.parameterIndex];
          }
          else {
               this.parameterAnnotations = new Annotation[0];
          }
     }
     return this.parameterAnnotations;
}"><pre class="notranslate"><code class="notranslate">public Annotation[] getParameterAnnotations() {
     if (this.parameterAnnotations == null) {
          Annotation[][] annotationArray = (this.method != null ?
                        this.method.getParameterAnnotations() : this.constructor.getParameterAnnotations());
          if (this.parameterIndex &gt;= 0 &amp;&amp; this.parameterIndex &lt; annotationArray.length) {
               this.parameterAnnotations = annotationArray[this.parameterIndex];
          }
          else {
               this.parameterAnnotations = new Annotation[0];
          }
     }
     return this.parameterAnnotations;
}
</code></pre></div>
<p dir="auto">results of calls on Method &amp; Constructor:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Annotation[][] annotationArray = (this.method != null ?
              this.method.getParameterAnnotations() : this.constructor.getParameterAnnotations());"><pre class="notranslate"><code class="notranslate">Annotation[][] annotationArray = (this.method != null ?
              this.method.getParameterAnnotations() : this.constructor.getParameterAnnotations());
</code></pre></div>
<p dir="auto">should be cached in two static Maps (since MethodParameter object is recreated per request)</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1 GA</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/19560/screenshot-1.jpg" rel="nofollow">screenshot-1.jpg</a> (<em>224.28 kB</em>)</li>
<li><a href="https://jira.spring.io/secure/attachment/19561/screenshot-2.jpg" rel="nofollow">screenshot-2.jpg</a> (<em>291.28 kB</em>)</li>
</ul>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398152908" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/14382" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/14382/hovercard" href="https://github.com/spring-projects/spring-framework/issues/14382">#14382</a> Share MethodParameter cache between HandlerMethods (<em><strong>"duplicates"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398112219" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12967" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12967/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12967">#12967</a> Look up of parameter annotations causes deadlock (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398114812" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13379" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13379/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13379">#13379</a> annotations need to be cached (jvm concurrency issue) (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto">0 votes, 7 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=pcl" rel="nofollow">Patrick Linskey</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9748?redirect=false" rel="nofollow">SPR-9748</a></strong> and commented</p>
<p dir="auto">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.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1.1, 3.1.2, 3.2 M2</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398118478" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13936" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13936/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13936">#13936</a> monitor contention at org.springframework.core.MethodParameter.getParameterAnnotations() (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398173917" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/17058" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/17058/hovercard" href="https://github.com/spring-projects/spring-framework/issues/17058">#17058</a> NPE in org.springframework.core.MethodParameter.getParameterName (possible race condition)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398177812" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/17429" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/17429/hovercard" href="https://github.com/spring-projects/spring-framework/issues/17429">#17429</a> Thread contention in HandlerMethod due to unnecessary BeanFactory.getType call</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/229537288a721ea1f73d7fee5ce9dd60ec46c23e/hovercard" href="https://github.com/spring-projects/spring-framework/commit/229537288a721ea1f73d7fee5ce9dd60ec46c23e"><tt>2295372</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/0a877afa061aacc67b238be6015bf82a3eecf0eb/hovercard" href="https://github.com/spring-projects/spring-framework/commit/0a877afa061aacc67b238be6015bf82a3eecf0eb"><tt>0a877af</tt></a></p>
<p dir="auto">1 votes, 3 watchers</p>