[Answer is based on comments]
Assuming, you want to process a list of String
and also want to store the response of each processing with input and output, then you can follow the below approach.
List<String> lines = FileUtils.readLines(dataFile,"UTF-8");
Map<String, String> result = lines.parallelStream()
.collect(Collectors.toMap(line -> line, line -> processRecord(line, dataFileName)));
Here, the result
(a simple Map<Key, Value>
) will contain both.. the key as each single line, and value as each single response of THAT line returned by processRecord
method.
how many threads will execute parallelly this method (from comments)
The method parallelStream()
uses threads form DefaultForkJoinPool
. And this pool has default size equal to the number of cores
on your system.