title: Split the large list into sub-list and apply the executors for parallel executio of sub-list using java
body: <p>I want to execute the large size list. its take too much time get the values. so i divided list as sublist then I want to run the all list parallelly.
  can we give some suggestion for that.</p>
  
  <p>Example :<br>
  Employee Class :  </p>
  
  <pre><code>public class Employee {
  
  private int eno;
  private String ename;
  private String desg;
  
  public Employee(int eno, String ename, String desg) {
      this.eno = eno;
      this.ename = ename;
      this.desg = desg;
  }
  
  public int getEno() {
      return eno;
  }
  
  public void setEno(int eno) {
      this.eno = eno;
  }
  
  public String getEname() {
      return ename;
  }
  
  public void setEname(String ename) {
      this.ename = ename;
  }
  
  public String getDesg() {
      return desg;
  }
  
  public void setDesg(String desg) {
      this.desg = desg;
  }
  
  /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
  @Override
  public String toString() {
      return "{eno=" + eno + ", ename=" + ename + ", desg=" + desg + "}";
    }
   }
  </code></pre>
  
  <p>Add Employees using below class :<br>
  Actually i am getting those values from webservices. sample i created below class</p>
  
  <pre><code>public class EmployeeTest  {
  
    public List&lt;Employee&gt; getEmployees() {
      List&lt;Employee&gt; employees = new ArrayList&lt;&gt;();
      for (int i = 1; i &lt;= 701; i++) {
          employees.add(new Employee(i, "s" + i, "sd" + i));
      }
      return employees;
    }
  }
  </code></pre>
  
  <p>I called list of employees and create sub-list each sub-list contain 100.
  I want to execute all sub-list parallel. Here I am getting 
        <code>java.lang.IndexOutOfBoundsException</code> because of 702 element not there. </p>
  
  <pre><code> public static void main(String[] args) throws InterruptedException {
  
      List&lt;Employee&gt; collect =  new EmployeeTest().getEmployees().parallelStream().collect(Collectors.toList());
      int partitionSize = 100;
      List&lt;List&lt;Employee&gt;&gt; partitions = new ArrayList&lt;&gt;();
      for(int i = 0; i &lt; collect.size();i += partitionSize){
          partitions.add(collect.subList(i,i + Math.min(partitionSize, collect.size() - i)));
      }
  
      for (List&lt;Employee&gt; list : partitions) {
          System.out.println(list.get(1));
      }
  }
  </code></pre>
  
  <p>how should i overcome this kind of error and how should i implements executors here for parallel execution of all list.</p>
  
  <p>output :    </p>
  
  <pre><code>   {eno=2, ename=s2, desg=sd2}
     {eno=102, ename=s102, desg=sd102}
     {eno=202, ename=s202, desg=sd202}
     {eno=302, ename=s302, desg=sd302}
     {eno=402, ename=s402, desg=sd402}
     {eno=502, ename=s502, desg=sd502}
     {eno=602, ename=s602, desg=sd602}
     Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
  at java.util.ArrayList$SubList.rangeCheck(ArrayList.java:1202)
  at java.util.ArrayList$SubList.get(ArrayList.java:1019)
  at com.employee.ExecuteServicesDemo.main(ExecuteServicesDemo.java:22)
  </code></pre>
  
  <p>Thanks !</p>