37 lines
849 B
Plaintext
37 lines
849 B
Plaintext
A Spring ``++singleton++`` bean may be used by many threads at once, and the use of instance (non-``++static++``) variables could cause concurrency issues.
|
|
|
|
|
|
This rule applies to classes with the following annotations: ``++@Service++``, ``++@Component++``, ``++@Repository++``, ``++@Scope("singleton")++``
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,java]
|
|
----
|
|
@Service("animalService")
|
|
public class AnimalService {
|
|
private int age = 1; // Noncompliant
|
|
private static int count = 0; // Compliant; static
|
|
|
|
@Inject
|
|
private AnimalDAO animalDAO; // Compliant; managed by Spring
|
|
...
|
|
}
|
|
----
|
|
|
|
|
|
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[]
|