Re:Java memes which refuse to die
by spacemanaki on Monday August 27, 2012 @12:41PM
(#4439604)
Thanks, I looked up the source and saw that append was synchronized too. I was mostly asking about this claim from the OP: "the JIT and JVM will attempt to hold onto the lock between calls in the interests of efficiency". I don't think that's true.
To ensure that only one thread executes those `append` at once, you would have to synchronize on the `StringBuffer` instance:
Then only one thread will do the appending at a time. But this introduce yet another lock in your code, and render the `synchronized` methods useless and redondant.