fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.concurrent.*;
  5.  
  6. /* Name of the class has to be "Main" only if the class is public. */
  7. class Ideone
  8. {
  9. public static void delay(){
  10. try{
  11. Thread.sleep(ThreadLocalRandom.current().nextInt(100,300));
  12. }catch(Exception ex){}
  13. }
  14.  
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17. List<String> orders = Arrays.asList("order1", "order2", "order3", "order4");
  18. List<String> rules = Arrays.asList("rule1", "rule2", "rule3");
  19. orders.stream().parallel().forEach(order->{
  20. rules.forEach(rule->{
  21. delay();
  22. System.out.println(order+"-"+rule);
  23. });
  24. });
  25. }
  26. }
Success #stdin #stdout 0.14s 37372KB
stdin
Standard input is empty
stdout
order3-rule1
order2-rule1
order2-rule2
order3-rule2
order3-rule3
order2-rule3
order1-rule1
order4-rule1
order1-rule2
order4-rule2
order4-rule3
order1-rule3