Am new to Spring.I have a spring bean countService which is a singleton
public class CountService {
private int doCount() {
String commentsText = null;
List tranIds = new ArrayList();
int count = 0;
// ---business logic----
return count;
}
}
Are the method variables commentsText,tranIds thread-safe?Thanks in advance
Spring or not, Java local variables are thread safe as long as you do not share their objects manually with other threads. For example, if your “business logic” code creates new threads and passes your local variables to these threads, the locals are not thread safe. Other than that, they are: each executing thread running your method will get its own local variable that is separate from all other local variables.