O'Reilly logo

Mastering Concurrency Programming with Java 9 - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Recommendation system - the main class

We have implemented our algorithm in the ConcurrentMainRecommendation class to obtain the list of recommended products to a customer. This class implements the main() method that receives as a parameter the ID of the customer whose recommended products we want to obtain. We have the following code:

public static void main(String[] args) { 
  String user = args[0]; 
  Path file = Paths.get("data"); 
  try { 
    Date start, end; 
    start=new Date(); 

We have used different streams to transform the data in the final solution. The first one loads the whole list of the Product objects from its files:

List<Product> productList = Files.walk(file, FileVisitOption                                 .FOLLOW_LINKS).parallel().filter(f-> f .toString().endsWith(".txt")) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required