Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others


0 votes
in Technique[技术] by (71.8m points)

java - Alternative of parallelstream to run method in parallel

I have been using a method with paralleStream() in order to perform some operations on files like translations and modification (different file types and size). But i have noticed parallelStream sometimes behaves in a wierd way giving me different exceptions or Error outputs printing in the output file instead of proper translations.

On changing parallelStream() to sequentialStream() it works fine. But the problem is , since it is CPU-intensive operations, i need to have better performance in terms of speed.

what is the alternative of parallelstream that would work better than that in such situation.

Use case : Modification of files

Translation of file content from one language to another, so it requires to parsing through each segment in order to do the translation for each segments from source locale to target language locale.

Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The alternatives of parallelStream you can try are ExecutorService and Fork/Join Framework.

Υou can find here the results of testing the above three options when taking into account different parameters (e.g. number of threads).

Now what is better in each case is relevant to the case and its parameters. As you can see from the results of those tests, parallelStream achieved both the best and the worst execution times. So, it really depends on the parameters of your case.

Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share