I need to write blocks of data (characters) and I don’t care about the sequence of those blocks. I wonder what kind of OutputStream I should use to achieve high performance?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Simply calling a vanilla ZipOutputStream from multiple threads would not work. The ZipOutputStream API has a model where you write entries one at a time as follows:
This model is inherently non-thread-safe.
In order to do this in a thread-safe fashion, you’d need to wrap the ZipOutputStream in a class that does the put/write/close operations in one synchronized method call. And that means that you are essentially doing your Zip output operations serially, which largely defeats your purpose for doing this.