79607297

Date: 2025-05-05 16:30:07
Score: 1
Natty:
Report link

This is possible with the new mapConcurrent method

public static <T, R> Gatherer<T, ?, R> mapConcurrent(int maxConcurrency, 
            Function<? super T, ? extends R> mapper)

so you would write something like this

paths.gather(Gatherers.mapConcurrent(100, p -> p))
    .filter(Files::isRegularFile)
    .filter(p -> p.toString().endsWith(".jpeg") || p.toString().endsWith(".jpg"))
    .forEach(this::resizeAndSaveImage);

Source: https://www.theserverside.com/tip/How-to-use-parallel-streams-in-Java-with-virtual-threads

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: CodesInTheDark