0

I'm using the method below and it takes lots of time (about 10 min.) when the list have about 1000 elements.If the list has 1 element, it takes 100ms Is there a way for improving the performance?

List<Book> books = Optional.ofNullable(library.getOnlineBooks).map(
                    onlineBooks-> onlineBooks.stream()
                            .filter(Objects::nonNull)
                            .map(onlineBook->
                                    searchCopys.search(onlineBook.getTitle())
                                            .map(copys-> BookCreator.create(onlineBook, copys)
                                            ).block())
                            .collect(Collectors.toList()))
                    .orElse(Collections.emptyList())

 Mono<Book> BookCreator create(OnlineBook onlineBook, Copys copys){
 }

 Mono<Copys> SearchCopys search(String title){
 }

Thanks

userit1985
  • 961
  • 1
  • 13
  • 28
  • 1
    You haven't provided enough code for us to be able to test this ourselves, so we'll only be able to make guesses for improvements. – Jacob G. Jun 24 '18 at 19:18
  • @JacobG. Hi, I believe the low performance cause due to the fact that the method inside the map return a Mono and for each book ,I do block. but I do not find any solution to solve this. – userit1985 Jun 24 '18 at 19:52
  • have you tried `onlineBooks.parallelStream()`? – dehasi Jun 24 '18 at 21:11
  • it looks like you have the performance problem here `searchCopys.search(onlineBook.getTitle())` do you have any change to profile/speed up this part? – dehasi Jun 24 '18 at 21:15
  • Have you try to optimize the method `Mono SearchCopys search(String title)` ? What does it do exactly? – Nguyen Phung Jul 03 '18 at 07:36
  • Or you can check this [post](https://stackoverflow.com/questions/34696884/performance-of-java-optional), I think it may provide a help or idea to you. – Nguyen Phung Jul 03 '18 at 07:41

0 Answers0