19 package org.sleuthkit.autopsy.datasourcesummary.uiutils;
21 import com.google.common.util.concurrent.ThreadFactoryBuilder;
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.concurrent.ExecutorService;
26 import java.util.concurrent.Executors;
27 import java.util.concurrent.Future;
28 import java.util.stream.Collectors;
29 import javax.swing.SwingWorker;
40 private final ExecutorService
executorService = Executors.newFixedThreadPool(1,
new ThreadFactoryBuilder().setNameFormat(
"SwingWorkerSequentialExecutor-%d").build());
41 private List<? extends SwingWorker<?, ?>>
workers = Collections.emptyList();
42 private List<Future<?>>
futures = Collections.emptyList();
50 public synchronized void submit(List<? extends SwingWorker<?, ?>> submittedWorkers) {
55 if (submittedWorkers == null) {
59 this.workers =
new ArrayList<>(submittedWorkers);
62 this.futures = this.workers.stream()
63 .map((w) -> executorService.submit(w))
64 .collect(Collectors.toList());
71 futures.forEach((f) -> f.cancel(
true));
72 workers = Collections.emptyList();
73 futures = Collections.emptyList();
85 for (Future<?> future : futures) {
86 if (!future.isDone()) {
List<?extends SwingWorker<?,?> > workers
List< Future<?> > futures
synchronized void cancelRunning()
synchronized boolean isRunning()
synchronized void submit(List<?extends SwingWorker<?,?>> submittedWorkers)
final ExecutorService executorService