== Why is this an issue?

Synchronization can be expensive in terms of time when multiple threads need to pass through the same bottleneck /``++synchronized++`` piece of code. 


If you have a piece of code calling a ``++synchronized++`` method once, then it only has to wait its turn to pass through the bottleneck once. But call it in a loop, and your code has to get back in line for the bottleneck over and over.


Instead, it would be better to get into the bottleneck, and then do the looping. I.e. consider refactoring the code to perform the loop inside the ``++synchronized++`` method.


This rule raises an issue when a ``++synchronized++`` method is called in a loop.


=== Noncompliant code example

[source,java]
----
public void doSomething(int max) {
  for (int i = 0; i < max; i++) {
    doSynchronized(i);  // Noncompliant
  }
}

public synchronized void doSynchronized(int val) {
  // ...
}
----


ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

include::../message.adoc[]

'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]

endif::env-github,rspecator-view[]
