Skip to content

ForkJoinPool inside KernelRunner causes explosive thread use when many kernels run #179

Description

@madhephaestus

When using the JTP mode to run a lot of kernels, i noticed that the thread count exploded. When i looked into the source it seems the KernelRunner instantiates a new thread pool to be used by its self, but never reused nor ever shut down.

There is no option to pass in a ForkJoinPool as a parameter, nor a flag to tell the KernelRunners to reuse existing ForkJoinPool instances.

My work around to make the reuse possible was to do this:

public static void setPrivateThreadPool(KernelRunner kernelRunner, ForkJoinPool newThreadPool) throws Exception {
        // Get the class of the object
        Class<?> clazz = kernelRunner.getClass();

        // Get the private field
        Field threadPoolField = clazz.getDeclaredField("threadPool");

        // Make it accessible
        threadPoolField.setAccessible(true);

        // Set the new value
        threadPoolField.set(kernelRunner, newThreadPool);
    }

    public static ForkJoinPool getPrivateThreadPool(KernelRunner kernelRunner) throws Exception {
        Class<?> clazz = kernelRunner.getClass();
        Field threadPoolField = clazz.getDeclaredField("threadPool");
        threadPoolField.setAccessible(true);
        return (ForkJoinPool) threadPoolField.get(kernelRunner);
    }

I would suggest a getter and setter for this field would resolve the issue i had specifically.

I would also suggest that a static default option would be a better default than constructing a new thread pool with each KernelRunner.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions