Closed dhoard closed 1 month ago
Summary
SemaphoreExecutor fails to execute a Runnable tasks
SemaphoreExecutor
Runnable
Expected Output
10 x Task is running System.out prints 10 x Task completed System.out prints
Task is running
Task completed
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"); } } }
Embarrassing bug. Fixed. Thanks!
Summary
SemaphoreExecutor
fails to execute aRunnable
tasksExpected Output
10 x
Task is running
System.out prints 10 xTask completed
System.out printsActual Output
no System.out prints
Test Code