Skip to content

Pause object has a static ExecutorService that can't be shutdown #268

@henri-tremblay

Description

@henri-tremblay

org.assertj.swing.timing.Pause has an ExecutorService. It's static and cannot be closed. It means that we have non-daemon threads hanging in there and preventing the JVM to finish.

An example is

    public static void main(String[] args) throws Exception {
        Pause.pause(new Condition("Cond") {
            @Override
            public boolean test() {
                return true;
            }
        });

        Field field = Pause.class.getDeclaredField("EXECUTOR_SERVICE");
        field.setAccessible(true);
        ExecutorService service = (ExecutorService) field.get(null);
        service.shutdownNow();
    }

Without the reflection code at the end, it won't exit for a while.

The easiest solution is to add a static close() method to shutdown the pool. But I think the best is to change the code to rely on the commonPool, e.g. ForkJoinPool.commonPool().submit() or a CompletableFuture.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions