From 9981865a0c466c74cdaadd65e3ab14e9c26cc0eb Mon Sep 17 00:00:00 2001 From: Benjamin Prud'homme Date: Sun, 4 Aug 2024 12:45:49 -0400 Subject: [PATCH 1/2] Fiber refactorigns --- .../illinois/library/cantaloupe/async/ThreadPool.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/edu/illinois/library/cantaloupe/async/ThreadPool.java b/src/main/java/edu/illinois/library/cantaloupe/async/ThreadPool.java index b3ee9ff19..e9a29a7e0 100644 --- a/src/main/java/edu/illinois/library/cantaloupe/async/ThreadPool.java +++ b/src/main/java/edu/illinois/library/cantaloupe/async/ThreadPool.java @@ -31,9 +31,7 @@ private String getThreadID() { abstract String getThreadNamePrefix(); public Thread newThread(Runnable runnable) { - Thread thread = new Thread(runnable); - thread.setName(getThreadNamePrefix() + "-" + getThreadID()); - thread.setDaemon(true); + Thread thread = Thread.ofVirtual().name(getThreadNamePrefix() + "-", Long.parseLong(getThreadID())).unstarted(runnable); return thread; } } @@ -66,11 +64,11 @@ String getThreadNamePrefix() { private boolean isShutdown = false; private final ExecutorService lowPriorityPool = - Executors.newCachedThreadPool(new LowPriorityThreadFactory()); + Executors.newThreadPerTaskExecutor(new LowPriorityThreadFactory()); private final ExecutorService normalPriorityPool = - Executors.newCachedThreadPool(new NormalPriorityThreadFactory()); + Executors.newThreadPerTaskExecutor(new NormalPriorityThreadFactory()); private final ExecutorService highPriorityPool = - Executors.newCachedThreadPool(new HighPriorityThreadFactory()); + Executors.newThreadPerTaskExecutor(new HighPriorityThreadFactory()); /** * @return Shared instance. From f433ad39bccd35ae9e49e811c43de893330476d3 Mon Sep 17 00:00:00 2001 From: Benjamin Prud'homme <139664105+bgprudhomme@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:05:18 -0400 Subject: [PATCH 2/2] Update ConcurrentReaderWriter.java --- .../library/cantaloupe/test/ConcurrentReaderWriter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/edu/illinois/library/cantaloupe/test/ConcurrentReaderWriter.java b/src/test/java/edu/illinois/library/cantaloupe/test/ConcurrentReaderWriter.java index ffed9fc37..b0112d43e 100644 --- a/src/test/java/edu/illinois/library/cantaloupe/test/ConcurrentReaderWriter.java +++ b/src/test/java/edu/illinois/library/cantaloupe/test/ConcurrentReaderWriter.java @@ -34,7 +34,7 @@ public ConcurrentReaderWriter(Callable writer, Callable reader, public void run() throws Exception { for (int i = 0; i < numThreads / 2f; i++) { - new Thread(() -> { // writer thread + Thread.ofVirtual().start(() -> { // writer thread try { writer.call(); } catch (Exception e) { @@ -43,9 +43,9 @@ public void run() throws Exception { } finally { writeCount.incrementAndGet(); } - }).start(); + }); - new Thread(() -> { + Thread.ofVirtual().start(() -> { while (true) { // Spin until we have something to read. if (writeCount.get() > 0) { @@ -62,7 +62,7 @@ public void run() throws Exception { sleep(1); } } - }).start(); + }); } while (readCount.get() < numThreads / 2f ||