[jdk24] RFR: 8347542: Gatherers.mapConcurrent exhibits undesired behavior under variable delays, interruption, and finishing

He-Pin (kerr) duke at openjdk.org
Mon Jan 13 19:23:39 UTC 2025


On Mon, 13 Jan 2025 12:59:06 GMT, Viktor Klang <vklang at openjdk.org> wrote:

> Backport to jdk24 of https://bugs.openjdk.org/browse/JDK-8347274

Does this fix the OOM problem?


import java.util.stream.Gatherers;
import java.util.stream.IntStream;

/**
 * TODO: description of this file
 *
 * @author 虎鸣
 */
public class Main {
    public static void main(String[] args) {
        final var stream = IntStream.range(0, Integer.MAX_VALUE);
        stream.boxed()
            .gather(Gatherers.mapConcurrent(
                2,
                i -> {
                    if (i == 0) {
                        try {
                            Thread.sleep(Integer.MAX_VALUE);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                    return i;
                }))
            .forEach(System.out::println);
        try {
            Thread.sleep(Integer.MAX_VALUE);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}

-------------

PR Comment: https://git.openjdk.org/jdk/pull/23068#issuecomment-2587998277


More information about the core-libs-dev mailing list