RESOLVED - issue BATCH-1405: Starvation of threads - TaskExecutorRepeatTemplate

Added test case looking for potential issue.
This commit is contained in:
dsyer
2009-09-16 08:27:25 +00:00
parent b689583ba8
commit 0940d1b9e3
2 changed files with 20 additions and 3 deletions

View File

@@ -260,6 +260,4 @@ public class TaskExecutorRepeatTemplateAsynchronousTests extends AbstractTradeBa
assertTrue(threadNames.size() >= 1);
}
// TODO: test transactional callback with async template.
}

View File

@@ -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 {