私はList<List<String>>
をJavaで持っています。親リスト内のリストを非同期的に固定スレッドプールの例3で処理します。CompletableFutureとStreamをJava 8で使用しようとしています。これらの2つをマージする方法と、 。 PFBコード私はこれまでに試したことがあります。プロセッサーでは印刷していますが、私はDB操作を行います。javaのCompletableFutureでリストのリストを処理するには?
ここでストリームList<List<String>>
を作成しようとしていますが、リストサイズに基づいてスレッド数を作成していますが、hoeはStreamed ListをCompletableFutureのProcessorに引数として渡します。
public class CompletableFutureWithList {
public static void main(String args[]) {
List<List<String>> aList = new ArrayList<>();
aList.add(new ArrayList<>(Arrays.asList("xyz", "abc")));
aList.add(new ArrayList<>(Arrays.asList("qwe", "poi")));
System.out.println("helo...");
ExecutorService executor = Executors.newFixedThreadPool(aList.size());
//aList.stream().flatMap(List::stream).
Processor aProcessor = new Processor();
List<String> tempList = new ArrayList<>();
CompletableFuture aComFuture = supplyAsync(() -> aProcessor.processList(tempList), executor);
try {
aComFuture.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
public class Processor {
public boolean processList(List<String> tempList) {
for (String string : tempList) {
System.out.println("Output: " + string);
}
return true;
}
}
なぜあなたはCompletableFutureを使用していて、単純に呼び出していない '将来 F = excecutor.submit(() - > PROCESSLIST(リスト))'各リストのために? –
assylias
1つのスレッド(デバッグが簡単)を持つシンプルなプログラムを作成し、このプログラムを使用して外部プロセスの実行に使用することができます。Apache Commons Exec。 – Grzesiek