1

I adopt a software architecture where I have one single data access in the persistence layer.

Indeed, the persistence layer is a mere java application (JAR file) that I consider as an dependency, thanks to Maven's POM.

So, when I need to access the database, I just call some DAO classes from some Servlet or such.

Since I am considering multithreading via Tomcat, I took advantage of StringBuffer, but SonarQube, which detects that my Back-End API is a mere Java-App, recommends to use StringBuilder instead.

Is SonarQube right, or should I stick to StringBuffer?

Or is multi-threading out-of-scope when it comes to APIs?

Robert Harvey
  • 198,589
  • 55
  • 464
  • 673
  • 3
    Possible duplicate of [When should I use StringBuilder or StringBuffer?](http://programmers.stackexchange.com/questions/162340/when-should-i-use-stringbuilder-or-stringbuffer) – gnat Aug 11 '16 at 17:24
  • 2
    [StringBuffer synchronisation is essentially fake](http://jeremymanson.blogspot.ru/2008/08/dont-use-stringbuffer.html): "It is just _pretend thread-safe_." It misleads programmer to think that things are thread safe when they actually aren't. From perspective of writing concurrent code it is not better than StringBuilder - or more precisely it's worse because it makes it harder to reason about concurrency – gnat Aug 11 '16 at 17:29
  • Does this answer your question? [When should I use StringBuilder or StringBuffer?](https://softwareengineering.stackexchange.com/questions/162340/when-should-i-use-stringbuilder-or-stringbuffer) – рüффп Oct 22 '20 at 08:05

0 Answers0