Questions tagged [parallelstream]
41 questions
0
votes
1 answer
Nested for loops inside a parallel for loops gives incorrect results
I am iterating the foreach loop using parallelStream but inside i have a list of nested for loops.
During iteration its giving incorrect result each time with different value.
I really needs this parallel for loop execution to increase…

Mohana Priya
- 11
- 3
0
votes
1 answer
How to throw Timeout exception for the task inside parallel stream
The code I want to achieve is as below:
StreamSupport.stream(jsonArray.spliterator(), true).forEach(s ->{
try {
//invoke other api and set timeout for its execution
}
catch(TimeoutException e) {
…

Usman Mohammed
- 109
- 1
- 9
0
votes
0 answers
Stop all threads of a parallelStream
I would like to interrupt all threads (“substreams”) of a Java parallelStream according to a condition verified by one of them.
Exemple : a little piece of code to assess time needed to find a six characters password. I iterate from 1 to ~19…
0
votes
0 answers
Comparison between sequential and parallel stream
Should I keep using parallel stream here or should I go with sequential stream. I have tested it on various environments. In my local it was considerably fast but in the test environment, it was slower. doc is a list of strings of size 30K appx.…

Bhanu Mittal
- 61
- 3
- 11
0
votes
0 answers
Java HashMap and Synchronization With ParallelStream
I have a Java HashMap that is normally read and modified by a single thread. When the thread writes to this map via put, I have the following bit of code that validates some preconditions:
void put(Set toAdd, long id) {
///…

Nizbel99
- 123
- 6
0
votes
1 answer
Parallel Stream and SpringSecurity
I have the following block of code:
myList.parallelStream().forEach(item -> {
//this external api call will use the current
//spring security to populate the headers with values
//that is extracted from jwt token
var response =…

Rye
- 33
- 5
0
votes
1 answer
How to synchronized one method when parallelStream call in Java?
I want to Synchronize functionB. I mean, when some Attriute object call functionA, there are always just run one of object's functionB in the same time. But functionC and functionD in each object can do it after functionB finished by themselves.
I…

hua
- 169
- 9
0
votes
0 answers
Java ParallelStream with Spring Data JPA
I'm trying to use Java's parallel streams to retrieve records form postgres using Spring Data JPA. If I use the non parallel stream method I get the expected number of results returned. If I use the parallel parallelStream method I get one less…

whizkey
- 11
- 2
0
votes
2 answers
How to Optimize the code after creating map
I want to make the second part work thanks for the help:)
If arraylist is ['A','a','B','C','C'] then dups:['A','a','C','C'] nondups: ['B']
I tried :
Map counts = nums.parallelStream()
.collect( Collectors.groupingBy( {k ->…

checked
- 82
- 10
0
votes
2 answers
Trying to use Map.values().parallelStream().forEach(list -> list.sort(comparator)) but get error: "Comparison method violates its general contract!"
I am trying to use multi-threading to sort arrays that are stored in a map. There are a large amount of records, ~3.1 million, and thus while I am attempting to sort these records in a single threaded for loop it takes many hours to complete. I'm…

Sam P
- 11
- 4
0
votes
1 answer
Terminate stream when value matches criteria, otherwise collect into a collection
I am using Java parallel streams for a chess engine. The stream is used to evaluate each chess Move in a given List of Moves. Each Move is mapped to an Integer representing the Move's value, then I collect all the Integers into a List and return the…

Allen
- 13
- 1
0
votes
0 answers
LocaleContextHolder returns only language-code without country-code
I am currently using LocaleContextHolder.getLocale() to get the locale.
But the issue is, sometimes it returns language-code without country-code.
For e.g. : sometimes en_US, and sometimes en only
What could be the possible reason ?
FYI : Running…

Vikas Gope
- 29
- 6
0
votes
1 answer
Modify local list in parallel stream java
I have a method like below:
public void method ()
{
List list1 = someOperation();
List list2;
long failedCount = 0;
for (String element : list1) {
try {
list2 =…

Ap1712
- 33
- 4
0
votes
1 answer
How to sort list in parallelStream?
Is there a way to sort a list using parallelStream()? I saw there are forEach and forEachOrdered. But I was checking if there is a way to sort as follows,
list.parallelStream().map().sorted().collect(Collectors.toList());

H Athukorala
- 739
- 11
- 32
0
votes
1 answer
Want to compare two Lists of records, save commons to a new list ,Records are around 1M and taking a lot of time to process
I'm processing 2 csv files and checking common entries and saving them into a new csv file .however the comparison is taking a lot of time.My approach is to first read all the data from files into ArrayList then using parallelStream over main list,…

Danial Kayani
- 27
- 2