-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use StringBuilder instead of StringBuffer as it offers high performan… #58
Conversation
Can one of the admins verify this patch? |
1 similar comment
Can one of the admins verify this patch? |
@@ -102,7 +102,7 @@ | |||
private static final String DEFAULT_MIME_TYPE = "text/plain"; | |||
|
|||
/** Buffer in which the message is constructed prior to sending */ | |||
private StringBuffer buffer = new StringBuffer(); | |||
private StringBuilder buffer = new StringBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too sure this change here, in this class is correct. The StringBuffer
is a thread-safe class whereas the StringBuilder
isn't. Having said that I haven't checked yet whether MailLogger class is expected to be thread safe nor have I checked its usage thoroughly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the parallel
task and things like our execute framework that spawns new threads, loggers need to be thread safe, But to be honest I don't think we've ever verified MailLogger
actually is.
@@ -377,7 +377,7 @@ public synchronized void run() { | |||
} | |||
|
|||
// now did any of the threads throw an exception | |||
exceptionMessage = new StringBuffer(); | |||
exceptionMessage = new StringBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking through the class I don't think exceptionMessage
needs to be an instance field at all, it could be a local variable in spinThreads
and get passed as an argument to processExceptions
without doing any harm. To me it seems it is only ever used by a single thread.
Most probably a further refactoring could get rid of the first*
instance fields as well and have processExceptions
return all their values nicely encapsulated in a single object - including the accumulated messages.
Overall, IMO, this can't be a general find/replace change and instead needs to be checked for individual places where the |
…ce in single thread places as it is generally the case.
Undo edits to src/main/org/apache/tools/ant/listener/MailLogger.java and src/main/org/apache/tools/ant/taskdefs/Parallel.java |
The changes to Please restrict your change to |
…ce in single thread places as it is generally the case.