
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
60 lines
1.3 KiB
Plaintext
60 lines
1.3 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Synchronizing at the method, rather than the block level could lead to problems when maintenance adds code to the method, perhaps inadvertently synchronizing it as well. Instead, synchronization should be applied to the smallest feasible block for optimum performance and maintainability.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
public class MyClass() {
|
|
|
|
public void synchronized doSomething() { // Noncompliant
|
|
// ...
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
public class MyClass() {
|
|
|
|
private Object lockObj = new Object();
|
|
|
|
public void doSomething() {
|
|
synchronized(lockObj) {
|
|
// ...
|
|
}
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Move synchronization to the block level
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 16 Jun 2015, 17:08:08 Nicolas Peru wrote:
|
|
Looks good, wondering with overlap or even catch 22 with some other RSPEC about not synchronizing on ``++this++``
|
|
|
|
=== on 16 Jun 2015, 19:06:00 Ann Campbell wrote:
|
|
The closest I'm finding is RSPEC-3067 [~nicolas.peru], and unfortunately "this" seems to be suppressed from JIRA's indexing :-(
|
|
|
|
If you have a specific RSpec in mind, can you give me another pointer toward it?
|
|
|
|
endif::env-github,rspecator-view[]
|