Skip to content

Commit c08e096

Browse files
authored
ParallelTaskGroup fixes (#541)
- use the correct ExecutorManager method, rather than suppressing a warning - remove a comment with incorrect information about ParallelTaskGroup being used only for Redshift (it is also used for Greenplum) - (x2) replace throws Exception with a more precise declaration - remove redundant extension of Callable - remove redundant generics - add missing annotations
1 parent 82ecf32 commit c08e096

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/task/ParallelTaskGroup.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
import com.google.common.base.Preconditions;
2020
import com.google.edwmigration.dumper.application.dumper.handle.Handle;
2121
import com.google.edwmigration.dumper.plugin.ext.jdk.concurrent.ExecutorManager;
22-
import java.util.concurrent.Callable;
22+
import java.io.IOException;
23+
import java.util.concurrent.ExecutionException;
24+
import javax.annotation.Nonnull;
25+
import javax.annotation.Nullable;
2326
import org.apache.commons.csv.CSVPrinter;
2427

25-
// Redshift is really slow, and is the only thing that uses this.
2628
public class ParallelTaskGroup extends TaskGroup {
2729

2830
public ParallelTaskGroup(String name) {
@@ -42,21 +44,21 @@ public void addTask(Task<?> task) {
4244
super.addTask(task);
4345
}
4446

45-
private static class TaskRunner<T> implements Callable<T> {
47+
private static class TaskRunner {
4648

47-
private final TaskRunContext context;
48-
private final Task<T> task;
49-
private final CSVPrinter printer;
49+
@Nonnull private final TaskRunContext context;
50+
@Nonnull private final Task<?> task;
51+
@Nonnull private final CSVPrinter printer;
5052

51-
public TaskRunner(TaskRunContext context, Task<T> task, CSVPrinter printer) {
53+
public TaskRunner(
54+
@Nonnull TaskRunContext context, @Nonnull Task<?> task, @Nonnull CSVPrinter printer) {
5255
this.context = context;
5356
this.task = task;
5457
this.printer = printer;
5558
}
5659

57-
@Override
58-
public T call() throws Exception {
59-
T result = context.runChildTask(task);
60+
public @Nullable Object call() throws IOException {
61+
Object result = context.runChildTask(task);
6062
TaskState state = context.getTaskState(task);
6163
synchronized (printer) {
6264
printer.printRecord(task, state);
@@ -66,15 +68,16 @@ public T call() throws Exception {
6668
}
6769

6870
@Override
69-
@SuppressWarnings(
70-
"FutureReturnValueIgnored") // It's an ExecutorManager, which tracks the Future internally.
71-
protected void doRun(TaskRunContext context, CSVPrinter printer, Handle handle) throws Exception {
71+
protected void doRun(
72+
@Nonnull TaskRunContext context, @Nonnull CSVPrinter printer, @Nonnull Handle handle)
73+
throws ExecutionException, InterruptedException {
7274
// Throws ExecutionException if any sub-task threw. However, runChildTask() is nothrow, so that
7375
// never happens.
7476
// We safely publish the CSVPrinter to the ExecutorManager.
7577
try (ExecutorManager executorManager = new ExecutorManager(context.getExecutorService())) {
7678
for (Task<?> task : getTasks()) {
77-
executorManager.submit(new TaskRunner<>(context, task, printer));
79+
TaskRunner runner = new TaskRunner(context, task, printer);
80+
executorManager.execute(runner::call);
7881
}
7982
}
8083
// We now, by the t-w-r, safely collect the CSVPrinter from the sub-threads.

0 commit comments

Comments
 (0)