Skip to content

Instantly share code, notes, and snippets.

@comchangs
Created June 3, 2020 17:24
Show Gist options
  • Select an option

  • Save comchangs/ace4e5643ca33ccce10e384a7ebafb28 to your computer and use it in GitHub Desktop.

Select an option

Save comchangs/ace4e5643ca33ccce10e384a7ebafb28 to your computer and use it in GitHub Desktop.

Revisions

  1. comchangs created this gist Jun 3, 2020.
    42 changes: 42 additions & 0 deletions StreamTest.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    import java.util.Arrays;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.stream.Stream;

    public class StreamTest {

    private static int MAX_ITERATION = 3_000;

    public static void main(String[] args) {
    List<String> list = new LinkedList<>();
    for (int i = 0; i < MAX_ITERATION; i++) {
    list.add(String.valueOf(i));
    }
    long start = 0, end = 0;

    long sum[] = {0};
    start = System.currentTimeMillis();
    Stream<String> streamToParallel = list.stream().parallel();
    streamToParallel.forEach(value -> {
    long s = System.currentTimeMillis();
    print(value);
    long e = System.currentTimeMillis() - s;
    //System.out.println(e);
    sum[0] = sum[0] + e;
    System.out.println(sum[0]);
    });
    end = System.currentTimeMillis();
    System.out.println("병렬처리: " + (end - start)); //병렬처리: 4282

    }

    public static void print(String str) {
    System.out.println(str+ " : "+Thread.currentThread().getName());
    try {
    Thread.sleep(10);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }

    }