Merge pull request #4882 from eclipse/jetty-9.4.x-4873-ExecutorThreadPoolJoin
Issue #4873 - fix timeout on ExecutorThreadPool.join()
This commit is contained in:
commit
4611379c86
|
@ -302,7 +302,7 @@ public class ExecutorThreadPool extends ContainerLifeCycle implements ThreadPool
|
|||
@Override
|
||||
public void join() throws InterruptedException
|
||||
{
|
||||
_executor.awaitTermination(getStopTimeout(), TimeUnit.MILLISECONDS);
|
||||
_executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,7 +18,11 @@
|
|||
|
||||
package org.eclipse.jetty.util.thread;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.eclipse.jetty.util.ProcessorUtils;
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
|
@ -26,6 +30,8 @@ import org.junit.jupiter.api.BeforeAll;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public abstract class AbstractThreadPoolTest
|
||||
|
@ -87,4 +93,26 @@ public abstract class AbstractThreadPoolTest
|
|||
|
||||
assertThat(pool.getMaxThreads(), Matchers.is(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinWithStopTimeout()
|
||||
{
|
||||
// ThreadPool must be an implement ContainerLifeCycle for this test to be valid.
|
||||
SizedThreadPool threadPool = newPool(3);
|
||||
if (!(threadPool instanceof ContainerLifeCycle))
|
||||
return;
|
||||
|
||||
final long stopTimeout = 100;
|
||||
((ContainerLifeCycle)threadPool).setStopTimeout(100);
|
||||
LifeCycle.start(threadPool);
|
||||
|
||||
// Verify that join does not timeout after waiting twice the stopTimeout.
|
||||
assertThrows(Throwable.class, () ->
|
||||
assertTimeoutPreemptively(Duration.ofMillis(stopTimeout * 2), threadPool::join)
|
||||
);
|
||||
|
||||
// After stopping the ThreadPool join should unblock.
|
||||
LifeCycle.stop(threadPool);
|
||||
assertTimeoutPreemptively(Duration.ofMillis(stopTimeout), threadPool::join);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue