I need to speed up my program and tried this by changing a .stream() to a .parallelStream().
cars is a list of car objects. I use the id of each car to create a JsonCurrent and then use this jsonCurrent to add a new element to to carList.
When I use .stream() this works just fine but with .parallelStream() it doesn't work. The debugger shows me that all fields of JsonCurrent are null when carService.createJson() is called.
cars.parallelStream().forEach(car -> {
JsonCurrent currentLocation = carPositionService.carPosition(car.getId());
carList.add(carService.createJson(car, calendarWeek, currentWeek, currentLocation));
});
.stream()
If cars has 60 objects, carList contains 60 objects like expected.
.parallelStream()
If cars has 60 objects, carList contains 36 objects.