title: How to parallelize loops with Java 8's Fork/Join framework
body: <p>How to parallelize loops with Java 8's Fork/Join framework. Accually I did not work with multiple threading . I read lots of question in SO .Now i am unable to implement the parallel processing of list in Java 8. Any one can help me ?</p>
  
  <p>I have tried somthing like from <a href="http://www.omsn.de/blog/how-to-parallelize-loops-with-java-7-fork-join-framework" rel="nofollow noreferrer">this link</a>.</p>
  
  <pre><code>routes.stream().parallel().forEach(this::doSomething);
  </code></pre>
  
  <p>Scenario like list based on routes list I need to devide the task and execute I need like insted of foreach loop I want parallel execution of based on array size. </p>
  
  <p>My problem is when  processing  the <code>updateSchedules</code>  service it is taking too much time. That is the reason I want to implement the threading concept here. <code>scheduleService.updateSchedules(originId, destinationId,req.getJourneyDate());</code> </p>
  
  <pre><code>for (Availabilities ar : routes) {
    try {
      log.info("Starting for bus" + ar);
      Bus bus = new Bus();
  
      // Get schedule list
      BitlaSchedules schedule = scheduleRepo
        .findByOriginIdAndDestinationIdAndScheduleIdAndTravelIdAndRouteId(originId, 
           destinationId, ar.getScheduleId(), ar.getTravelId(), ar.getRouteId());
  
      if (schedule == null) {
        scheduleService.updateSchedules(originId, destinationId,req.getJourneyDate());
        schedule = scheduleRepo
          .findByOriginIdAndDestinationIdAndScheduleIdAndTravelIdAndRouteId(originId, 
            destinationId, ar.getScheduleId(), ar.getTravelId(), ar.getRouteId());
      }
    } catch(Exception e) {
      log.error(e.getMessage());
    }
  }
  </code></pre>