ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/SubmissionPublisherLoops1.java
(Generate patch)

Comparing jsr166/src/test/loops/SubmissionPublisherLoops1.java (file contents):
Revision 1.1 by dl, Thu Jul 23 11:13:47 2015 UTC vs.
Revision 1.4 by dl, Sat Sep 12 20:30:46 2015 UTC

# Line 18 | Line 18 | public class SubmissionPublisherLoops1 {
18  
19      static final Phaser phaser = new Phaser(CONSUMERS + 1);
20  
21 <    static class Sub implements Flow.Subscriber<Boolean> {
21 >    static final class Sub implements Flow.Subscriber<Boolean> {
22          Flow.Subscription sn;
23          int count;
24 <        public void onSubscribe(Flow.Subscription s) {
25 <            (sn = s).request(CAP);
24 >        public void onSubscribe(Flow.Subscription s) {
25 >            (sn = s).request(CAP);
26          }
27 <        public void onNext(Boolean t) {
27 >        public void onNext(Boolean t) {
28              if ((++count & (CAP - 1)) == (CAP >>> 1))
29                  sn.request(CAP);
30          }
31          public void onError(Throwable t) { t.printStackTrace(); }
32 <        public void onComplete() {
32 >        public void onComplete() {
33              if (count != ITEMS)
34                  System.out.println("Error: remaining " + (ITEMS - count));
35 <            phaser.arrive();
35 >            phaser.arrive();
36          }
37      }
38  
# Line 42 | Line 42 | public class SubmissionPublisherLoops1 {
42          int reps = REPS;
43          if (args.length > 0)
44              reps = Integer.parseInt(args[0]);
45 <        
46 <        System.out.println("ITEMS: " + ITEMS +
45 >
46 >        System.out.println("ITEMS: " + ITEMS +
47                             " CONSUMERS: " + CONSUMERS +
48                             " CAP: " + CAP);
49          ExecutorService exec = ForkJoinPool.commonPool();
50 <        for (int rep = 0; rep < reps; ++reps) {
51 <            long startTime = System.nanoTime();
52 <            final SubmissionPublisher<Boolean> pub =
53 <                new SubmissionPublisher<Boolean>(exec, CAP);
54 <            for (int i = 0; i < CONSUMERS; ++i)
55 <                pub.subscribe(new Sub());
56 <            for (int i = 0; i < ITEMS; ++i) {
57 <                pub.submit(Boolean.TRUE);
58 <            }
59 <            pub.close();
60 <            phaser.arriveAndAwaitAdvance();
61 <            long elapsed = System.nanoTime() - startTime;
62 <            double secs = ((double)elapsed) / NPS;
63 <            System.out.printf("\tTime: %7.3f\n", secs);
64 <            //            System.out.println(exec);
50 >        for (int rep = 0; rep < reps; ++rep) {
51 >            oneRun(exec);
52              Thread.sleep(1000);
53          }
54          if (exec != ForkJoinPool.commonPool())
55              exec.shutdown();
56      }
57 +
58 +    static void oneRun(ExecutorService exec) throws Exception {
59 +        long startTime = System.nanoTime();
60 +        final SubmissionPublisher<Boolean> pub =
61 +            new SubmissionPublisher<Boolean>(exec, CAP);
62 +        for (int i = 0; i < CONSUMERS; ++i)
63 +            pub.subscribe(new Sub());
64 +        for (int i = 0; i < ITEMS; ++i) {
65 +            pub.submit(Boolean.TRUE);
66 +        }
67 +        pub.close();
68 +        phaser.arriveAndAwaitAdvance();
69 +        long elapsed = System.nanoTime() - startTime;
70 +        double secs = ((double)elapsed) / NPS;
71 +        System.out.printf("\tTime: %7.3f\n", secs);
72 +    }
73   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines