#2582 - Fix for regression, BackgroundExecutor is bounded (since 12.6.2)

The change for #2121 brought in a regression where the scheduledExecutorService was used for processing ALL submitted tasks (not just scheduled ones) and is a bounded executor service.  Previously non-scheduled tasks went to a "newCachedThreadPool" based executor service and with this change we are moving back to that (via restoring and using the DaemonExecutorService for those tasks).
This commit is contained in:
Rob Bygrave
2022-03-04 10:21:56 +13:00
parent 61f5442e3b
commit e3a20a351d
3 changed files with 138 additions and 16 deletions
@@ -0,0 +1,56 @@
package io.ebeaninternal.server.executor;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
import static org.assertj.core.api.Assertions.assertThat;
class DaemonExecutorServiceTest {
private final int count = 10;
private final int waitMillis = 100;
@Test
void submit() throws Exception {
DaemonExecutorService des = new DaemonExecutorService(5, "junk");
long start = System.currentTimeMillis();
List<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < count; i++) {
futures.add(des.submit(this::doStuff));
}
for (Future<?> f: futures) {
f.get();
}
long exeMillis = System.currentTimeMillis() - start;
assertThat(exeMillis).isLessThan(count * waitMillis);
des.shutdown();
}
@Test
void submit_via_DefaultBackgroundExecutor() throws Exception {
DefaultBackgroundExecutor des = new DefaultBackgroundExecutor(1, 5, "junk");
long start = System.currentTimeMillis();
List<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < count; i++) {
futures.add(des.submit(this::doStuff));
}
for (Future<?> f: futures) {
f.get();
}
long exeMillis = System.currentTimeMillis() - start;
assertThat(exeMillis).isLessThan(count * waitMillis);
des.shutdown();
}
private void doStuff() {
try {
Thread.sleep(waitMillis);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}