fork(3) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.stream.Stream;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. Stream.of(1, 2).parallel()
  11. .peek(x -> System.out.println("processing "+x+" in "+Thread.currentThread()))
  12. .forEach(System.out::println);
  13. }
  14. }
Success #stdin #stdout 0.13s 4452352KB
stdin
Standard input is empty
stdout
processing 2 in Thread[main,5,main]
2
processing 1 in Thread[ForkJoinPool.commonPool-worker-1,5,main]
1