-
Notifications
You must be signed in to change notification settings - Fork 9
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
StringBuilderAsBuffer #2
Comments
So, where are we with this? Do you want this done using existing classes? Some points to consider:
And also passing around the big buffer among 3 classes is intentional as it saves the object being copied to multiple memory areas and using that much extra space, especially when memory allocation can really make or break this application. |
OK, I see your synchronise around the StringBuilder. But I still don't understand the complexity of your code. Did you originally start with a FileWriter from Java and found the performance lacking? My understanding of FileWriter is that it is exactly what you wrote: a Java thread which handles writing, buffer locking between threads and has a variable size buffer. If your code works, I'll merge it as is. But later on I'll probably rewrite it to use JDK classes and Apache libraries which have had thousands of hours of optimisation and testing effort. Unless you tell me that you already tried java.io.FileWriter and there were problems with it. |
This is really bad. StringBuilder must not be used by multiple threads:
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/StringBuilder.html
Java already has classes to do what you have reinvented from scratch such as... http://docs.oracle.com/javase/6/docs/api/java/io/FileWriter.html
If you used this, you would have no need to create multiple threads for reading and writing since Java will internally deal with the buffering for you.
The text was updated successfully, but these errors were encountered: