Skip to content

SemaphoreExecutor fails to execute Runnable tasks #26

@dhoard

Description

@dhoard

Summary

SemaphoreExecutor fails to execute a Runnable tasks

Expected Output

10 x Task is running System.out prints
10 x Task completed System.out prints

Actual Output

no System.out prints

Test Code

import io.github.thunkware.vt.bridge.ExecutorTool;
import io.github.thunkware.vt.bridge.SemaphoreExecutor;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

public class ExecutorServiceExample {

    public static void main(String[] args) {
        ExecutorService executor = new SemaphoreExecutor(ExecutorTool.newVirtualThreadPerTaskExecutor(), 2);
        List<Future<?>> futures = new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            Future<?> future = executor.submit(new RunnableTask());
            futures.add(future);
        }

        for (Future<?> future : futures) {
            try {
                future.get();
            } catch (Exception e) {
                e.printStackTrace(System.err);
            }
        }

        executor.shutdown();
    }

    private static class RunnableTask implements Runnable {

        @Override
        public void run() {
            System.out.println("Task is running");

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }

            System.out.println("Task completed");
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions