What actual cause the StringBuilder fails in multi threading environment
问题 StringBuffer is synchronized but StringBuilder is not ! This has been discussed deeply at Difference between StringBuilder and StringBuffer. There is an example code there (Answered by @NicolasZozol), which address two issues: compares the performance of these StringBuffer and StringBuilder shows the StringBuilder could fail in a multithread environment. My question is about second part , exactly what makes it to go wrong?! When you run the code some times, the stack trace is displayed as