private List<String> processLinesWithLogFilter(List<String> lines) {
return lines.stream()
.map(logFilter::filter)
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
List<String> lines is a huge list which contains from 300,000 to 1,000,000. My purpose is to filter out the huge log file and be selective on what I would like to be included.
The above code is what is causing high CPU utilization in the java application. I would like to reduce it by any method. I do not mind it taking longer than expected as long as CPU utilization is not high.
This is what logFilter::filter method contains
public Optional<String> filter(String log) {
return extractor.extract(log).filter(filter::isServiceLog).map(printer::printer);
extract method grabs the log file using StringBuilder, filter method uses Filter object using Matchers.
Is there a way to lower the CPU Utilization?
I tried using batch process which divides up the work. It did take longer than the original process but CPU Utilization did not get better.