407075 Do not dispatch from complete
Call HttpChannel.handle directly from thread calling complete
This commit is contained in:
parent
215f3f1f56
commit
98d260dd92
|
@ -405,7 +405,7 @@ public class HttpChannelState
|
||||||
public void complete()
|
public void complete()
|
||||||
{
|
{
|
||||||
// just like resume, except don't set _dispatched=true;
|
// just like resume, except don't set _dispatched=true;
|
||||||
boolean dispatch;
|
boolean handle;
|
||||||
synchronized (this)
|
synchronized (this)
|
||||||
{
|
{
|
||||||
switch(_state)
|
switch(_state)
|
||||||
|
@ -421,7 +421,7 @@ public class HttpChannelState
|
||||||
|
|
||||||
case ASYNCWAIT:
|
case ASYNCWAIT:
|
||||||
_state=State.COMPLETECALLED;
|
_state=State.COMPLETECALLED;
|
||||||
dispatch=!_expired;
|
handle=!_expired;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -429,10 +429,14 @@ public class HttpChannelState
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dispatch)
|
if (handle)
|
||||||
{
|
{
|
||||||
cancelTimeout();
|
cancelTimeout();
|
||||||
scheduleDispatch();
|
ContextHandler handler=getContextHandler();
|
||||||
|
if (handler!=null)
|
||||||
|
handler.handle(_channel);
|
||||||
|
else
|
||||||
|
_channel.handle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -599,7 +603,11 @@ public class HttpChannelState
|
||||||
{
|
{
|
||||||
final AsyncContextEvent event=_event;
|
final AsyncContextEvent event=_event;
|
||||||
if (event!=null)
|
if (event!=null)
|
||||||
return ((Context)event.getServletContext()).getContextHandler();
|
{
|
||||||
|
Context context=((Context)event.getServletContext());
|
||||||
|
if (context!=null)
|
||||||
|
return context.getContextHandler();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -458,7 +458,9 @@ public class StatisticsHandlerTest
|
||||||
{
|
{
|
||||||
final long dispatchTime = 10;
|
final long dispatchTime = 10;
|
||||||
final AtomicReference<AsyncContext> asyncHolder = new AtomicReference<>();
|
final AtomicReference<AsyncContext> asyncHolder = new AtomicReference<>();
|
||||||
final CyclicBarrier barrier[] = {new CyclicBarrier(2), new CyclicBarrier(2), new CyclicBarrier(2)};
|
final CyclicBarrier barrier[] = {new CyclicBarrier(2), new CyclicBarrier(2)};
|
||||||
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|
||||||
_statsHandler.setHandler(new AbstractHandler()
|
_statsHandler.setHandler(new AbstractHandler()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -540,7 +542,7 @@ public class StatisticsHandlerTest
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
barrier[2].await();
|
latch.countDown();
|
||||||
}
|
}
|
||||||
catch (Exception ignored)
|
catch (Exception ignored)
|
||||||
{
|
{
|
||||||
|
@ -550,7 +552,7 @@ public class StatisticsHandlerTest
|
||||||
long requestTime = 20;
|
long requestTime = 20;
|
||||||
Thread.sleep(requestTime);
|
Thread.sleep(requestTime);
|
||||||
asyncHolder.get().complete();
|
asyncHolder.get().complete();
|
||||||
barrier[2].await();
|
latch.await();
|
||||||
|
|
||||||
assertEquals(1, _statsHandler.getRequests());
|
assertEquals(1, _statsHandler.getRequests());
|
||||||
assertEquals(0, _statsHandler.getRequestsActive());
|
assertEquals(0, _statsHandler.getRequestsActive());
|
||||||
|
|
Loading…
Reference in New Issue