Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential NPE from VirtualThreadPool #12198

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class VirtualThreadPool extends ContainerLifeCycle implements ThreadPool,
private Thread _keepAlive;
private Executor _virtualExecutor;
private boolean _externalExecutor;
private Semaphore _semaphore;
private volatile Semaphore _semaphore;

public VirtualThreadPool()
{
Expand Down Expand Up @@ -255,7 +255,8 @@ public boolean tryExecute(Runnable task)
public void execute(Runnable task)
{
Runnable job = task;
if (_semaphore != null)
Semaphore semaphore = _semaphore;
if (semaphore != null)
{
job = () ->
{
Expand All @@ -265,7 +266,7 @@ public void execute(Runnable task)
// as it is unknown whether it is a virtual thread.
// But this is a virtual thread, so acquiring a permit here
// blocks the virtual thread, but does not pin the carrier.
_semaphore.acquire();
semaphore.acquire();
task.run();
}
catch (InterruptedException x)
Expand All @@ -276,7 +277,7 @@ public void execute(Runnable task)
}
finally
{
_semaphore.release();
semaphore.release();
}
};
}
Expand Down
Loading