There are two methods in Java8’s stream, namely the parallelStream() and Stream() methods. As the name suggests, one processes data in a parallel manner, and the other processes data in a traditional serial manner. The underlying principles of these two streams are available online. There is already a lot of introduction, so I won’t go into details here. I will just briefly talk about the usage scenarios.

During the actual use of the project, we found that if the data operations include adding, deleting, and modifying, the data results may be very wrong, so it is recommended to only use it when querying data.

This is because although the parallelStream() method is parallel processing, it is thread-unsafe and can be used in query operations to improve query speed. If used in operations that change data, data errors will occur.

发表回复

Thanks for your support to bet365fans!