Bug #73595 Replace usage of StringBuffer in JDBC driver
Submitted: 15 Aug 2014 8:12 Modified: 23 Jan 2015 0:23
Reporter: Lukas Eder Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S5 (Performance)
Version:5.1.32 OS:Any
Assigned to: Alexander Soklakov CPU Architecture:Any
Tags: jdbc, StringBuffer

[15 Aug 2014 8:12] Lukas Eder
Description:
While introspecting the sources of com.mysql.jdbc.DatabaseMetaDataUsingInfoSchema, I have discovered that in order to construct SQL strings internally, java.lang.StringBuffer is used instead of java.lang.StringBuilder.

StringBuffer's use is discouraged since JDK 5 as all of its methods are (most often unnecessarily) synchronized. See also the relevant paragraph of the StringBuffer Javadoc:

> As of release JDK 5, this class has been supplemented 
> with an equivalent class designed for use by a single 
> thread, StringBuilder. The StringBuilder class should 
> generally be used in preference to this one, as it 
> supports all of the same operations but it is faster, 
> as it performs no synchronization.

How to repeat:
No steps needed

Suggested fix:
Replace all single-threaded usage of StringBuffer in the JDBC driver by StringBuilder
[19 Aug 2014 11:11] Filipe Silva
Hi Lukas,

Thank you for this bug report.

We have been replacing StringBuffer by StringBuilder for some time, but there are still many to replace. So, it was verified as described.
[23 Jan 2015 0:23] Daniel So
Added the following entry to the Connector/J 5.1.35 changelog:

"All occurrences of the StringBuffer class in the Connector/J code has been replaced with the StringBuilder class, in order to improve code performance."