RESOLVED - issue BATCH-1405: Starvation of threads - TaskExecutorRepeatTemplate
Added test case looking for potential issue.
This commit is contained in:
@@ -260,6 +260,4 @@ public class TaskExecutorRepeatTemplateAsynchronousTests extends AbstractTradeBa
|
||||
assertTrue(threadNames.size() >= 1);
|
||||
}
|
||||
|
||||
// TODO: test transactional callback with async template.
|
||||
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class TaskExecutorRepeatTemplateSimpleAsynchronousTests {
|
||||
|
||||
public RepeatStatus doInIteration(RepeatContext context) throws Exception {
|
||||
int position = count.incrementAndGet();
|
||||
String item = position <= TOTAL ? "" + count : null;
|
||||
String item = position <= TOTAL ? "" + position : null;
|
||||
items.add("" + item);
|
||||
if (item != null) {
|
||||
beBusy();
|
||||
@@ -124,6 +124,25 @@ public class TaskExecutorRepeatTemplateSimpleAsynchronousTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThrottleLimitEarlyFinishThreadStarvation() throws Exception {
|
||||
|
||||
early = 2;
|
||||
SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
|
||||
// Set the concurrency limit below the throttle limit for possible starvation condition
|
||||
taskExecutor.setConcurrencyLimit(20);
|
||||
template.setTaskExecutor(taskExecutor);
|
||||
|
||||
template.iterate(callback);
|
||||
int frequency = Collections.frequency(items, "null");
|
||||
// System.err.println("Frequency: " + frequency);
|
||||
// System.err.println("Items: " + items);
|
||||
// One extra task will be submitted before the termination is detected
|
||||
assertEquals(TOTAL, items.size() - frequency);
|
||||
assertTrue(frequency <= throttleLimit + 1);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThrottleLimitEarlyFinishOneThread() throws Exception {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user