Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.concurrent.ForkJoinPool;
- import java.util.concurrent.RecursiveAction;
- public class ForkJoin {
- public static void main(String[] args) {
- byte a[] = new byte[256];
- byte b[] = new byte[256];
- // a, b代入
- ForkJoinPool pool = new ForkJoinPool();
- pool.invoke(new MyAction(a, b, 0, a.length - 1));
- }
- private static class MyAction extends RecursiveAction {
- private static final long serialVersionUID = 1L;
- private final byte a[];
- private final byte b[];
- private final int start;
- private final int end;
- MyAction(byte a[], byte b[], int start, int end) {
- this.a = a;
- this.b = b;
- this.start = start;
- this.end = end;
- }
- @Override
- protected void compute() {
- if (end - start == 0) {
- a[start] &= b[start];
- } else {
- invokeAll(new MyAction(a, b, start, start + (end - start) / 2),
- new MyAction(a, b, start + (end - start) / 2 + 1, end));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement