mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#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:
+56
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user