Comment detail

疑似並行処理 (Nested Flatten)
java.util.concurrent.* ベースで作りました。切り替えは単純に Thread.yield() しようかと思ったんですが、程よく混ざらないので「いっせ~の、せ!」で実行させるために無駄に CyclicBarrier です。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.concurrent.*;
public class test {
    public static void main(String[] args) {
        ExecutorService executor = Executors.newCachedThreadPool();
        final CyclicBarrier barrier = new CyclicBarrier(2);
        try {
            // その1
            executor.submit(new Callable<Object>(){
                public Object call() throws Exception {
                    for(int i = 1; i <= 10; i++) {
                        barrier.await();
                        System.out.println(i);
                    }
                    return null;
                }
            });
            // その2
            executor.submit(new Callable<Object>(){
                public Object call() throws Exception {
                    for(char c = 'A'; c <= 'J'; c++) {
                        barrier.await();
                        System.out.println(c);
                    }
                    return null;
                }
            });
        }
        finally {
            executor.shutdown();
        }
    }
}

Index

Feed

Other

Link

Pathtraq

loading...