Fixes #2451 - Review ReservedThreadExecutor.getAvailable().

Fixed by having getAvailable() returning _stack.size().

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2018-04-17 16:29:46 +02:00
parent f36eba4577
commit fac93fa7f8
2 changed files with 6 additions and 21 deletions

View File

@ -120,7 +120,7 @@ public class ReservedThreadExecutor extends AbstractLifeCycle implements TryExec
@ManagedAttribute(value = "available reserved threads", readonly = true)
public int getAvailable()
{
return _size.get();
return _stack.size();
}
@ManagedAttribute(value = "pending reserved threads", readonly = true)

View File

@ -18,13 +18,8 @@
package org.eclipse.jetty.util.thread;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
@ -36,6 +31,10 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class ReservedThreadExecutorTest
{
private static final int SIZE = 2;
@ -71,7 +70,7 @@ public class ReservedThreadExecutorTest
}
@Test
public void testStarted() throws Exception
public void testStarted()
{
// Reserved threads are lazily started.
assertThat(_executor._queue.size(), is(0));
@ -167,19 +166,6 @@ public class ReservedThreadExecutorTest
assertThat(_reservedExecutor.getAvailable(),is(0));
}
protected void waitForNoPending() throws InterruptedException
{
long started = System.nanoTime();
while (_reservedExecutor.getPending() > 0)
{
long elapsed = System.nanoTime() - started;
if (elapsed > TimeUnit.SECONDS.toNanos(10))
Assert.fail("pending="+_reservedExecutor.getPending());
Thread.sleep(10);
}
assertThat(_reservedExecutor.getPending(), is(0));
}
protected void waitForAvailable(int size) throws InterruptedException
{
long started = System.nanoTime();
@ -248,7 +234,6 @@ public class ReservedThreadExecutorTest
reserved.start();
final int LOOPS = 1000000;
final Random random = new Random();
final AtomicInteger executions = new AtomicInteger(LOOPS);
final CountDownLatch executed = new CountDownLatch(executions.get());
final AtomicInteger usedReserved = new AtomicInteger(0);