Advertisement
Guest User

Untitled

a guest
Oct 27th, 2011
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1.  
  2. import java.util.concurrent.ForkJoinPool;
  3. import java.util.concurrent.RecursiveAction;
  4.  
  5. public class ForkJoin {
  6.  
  7.     public static void main(String[] args) {
  8.         byte a[] = new byte[256];
  9.         byte b[] = new byte[256];
  10.  
  11.         // a, b代入
  12.  
  13.         ForkJoinPool pool = new ForkJoinPool();
  14.         pool.invoke(new MyAction(a, b, 0, a.length - 1));
  15.     }
  16.  
  17.     private static class MyAction extends RecursiveAction {
  18.         private static final long serialVersionUID = 1L;
  19.  
  20.         private final byte a[];
  21.         private final byte b[];
  22.         private final int start;
  23.         private final int end;
  24.  
  25.         MyAction(byte a[], byte b[], int start, int end) {
  26.             this.a = a;
  27.             this.b = b;
  28.             this.start = start;
  29.             this.end = end;
  30.         }
  31.  
  32.         @Override
  33.         protected void compute() {
  34.             if (end - start == 0) {
  35.                 a[start] &= b[start];
  36.             } else {
  37.                 invokeAll(new MyAction(a, b, start, start + (end - start) / 2),
  38.                         new MyAction(a, b, start + (end - start) / 2 + 1, end));
  39.             }
  40.         }
  41.     }
  42. }
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement