LoginSignup
5
2

More than 5 years have passed since last update.

【ネタ】Java で Sleep Sort

Posted at

http://qiita.com/lovee/items/9701151633d61e7ed4e3
http://qiita.com/takustaqu/items/412d6c36534b1145a024

というのがあったので、Java版です。

int[] array = {5, 3, 6, 3, 6, 3, 1, 4, 7};

 new ForkJoinPool(array.length).submit(() -> {
    IntStream.of(array).parallel().forEach(n -> {

        try {
            TimeUnit.SECONDS.sleep(n);
            System.out.println(n);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    });
}).get();

/* 出力:
1
3
3
3
4
5
6
6
7
*/

#parallelStream のスレッド数に上限あるの気付かんで少し苦戦した...

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2