Change "synchronized" to reentrant lock for virtual-threads
This commit is contained in:
@@ -57,7 +57,7 @@ public class ServerlessAsyncContext implements AsyncContext {
|
|||||||
|
|
||||||
private final List<Runnable> dispatchHandlers = new ArrayList<>();
|
private final List<Runnable> dispatchHandlers = new ArrayList<>();
|
||||||
|
|
||||||
private static final ReentrantLock globalLock = new ReentrantLock();
|
private final ReentrantLock globalLock = new ReentrantLock();
|
||||||
|
|
||||||
|
|
||||||
public ServerlessAsyncContext(ServletRequest request, @Nullable ServletResponse response) {
|
public ServerlessAsyncContext(ServletRequest request, @Nullable ServletResponse response) {
|
||||||
@@ -69,7 +69,7 @@ public class ServerlessAsyncContext implements AsyncContext {
|
|||||||
public void addDispatchHandler(Runnable handler) {
|
public void addDispatchHandler(Runnable handler) {
|
||||||
Assert.notNull(handler, "Dispatch handler must not be null");
|
Assert.notNull(handler, "Dispatch handler must not be null");
|
||||||
try {
|
try {
|
||||||
globalLock.lock();
|
this.globalLock.lock();
|
||||||
if (this.dispatchedPath == null) {
|
if (this.dispatchedPath == null) {
|
||||||
this.dispatchHandlers.add(handler);
|
this.dispatchHandlers.add(handler);
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ public class ServerlessAsyncContext implements AsyncContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
globalLock.unlock();
|
this.globalLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,12 +111,12 @@ public class ServerlessAsyncContext implements AsyncContext {
|
|||||||
@Override
|
@Override
|
||||||
public void dispatch(@Nullable ServletContext context, String path) {
|
public void dispatch(@Nullable ServletContext context, String path) {
|
||||||
try {
|
try {
|
||||||
globalLock.lock();
|
this.globalLock.lock();
|
||||||
this.dispatchedPath = path;
|
this.dispatchedPath = path;
|
||||||
this.dispatchHandlers.forEach(Runnable::run);
|
this.dispatchHandlers.forEach(Runnable::run);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
globalLock.unlock();
|
this.globalLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user