Skip to content

Commit 394bc13

Browse files
authored
Merge pull request #12198 from jetty/jetty-12.0.x-VirtualThreadPoolSemaphore
Fix potential NPE from VirtualThreadPool
2 parents 0f28d47 + 4fd306f commit 394bc13

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/VirtualThreadPool.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class VirtualThreadPool extends ContainerLifeCycle implements ThreadPool,
4646
private Thread _keepAlive;
4747
private Executor _virtualExecutor;
4848
private boolean _externalExecutor;
49-
private Semaphore _semaphore;
49+
private volatile Semaphore _semaphore;
5050

5151
public VirtualThreadPool()
5252
{
@@ -255,7 +255,8 @@ public boolean tryExecute(Runnable task)
255255
public void execute(Runnable task)
256256
{
257257
Runnable job = task;
258-
if (_semaphore != null)
258+
Semaphore semaphore = _semaphore;
259+
if (semaphore != null)
259260
{
260261
job = () ->
261262
{
@@ -265,7 +266,7 @@ public void execute(Runnable task)
265266
// as it is unknown whether it is a virtual thread.
266267
// But this is a virtual thread, so acquiring a permit here
267268
// blocks the virtual thread, but does not pin the carrier.
268-
_semaphore.acquire();
269+
semaphore.acquire();
269270
task.run();
270271
}
271272
catch (InterruptedException x)
@@ -276,7 +277,7 @@ public void execute(Runnable task)
276277
}
277278
finally
278279
{
279-
_semaphore.release();
280+
semaphore.release();
280281
}
281282
};
282283
}

0 commit comments

Comments
 (0)