24 |
|
int reps = REPS; |
25 |
|
if (args.length > 0) |
26 |
|
reps = Integer.parseInt(args[0]); |
27 |
< |
|
28 |
< |
System.out.println("ITEMS: " + ITEMS + |
29 |
< |
" PRODUCERS: " + PRODUCERS + |
27 |
> |
|
28 |
> |
System.out.println("ITEMS: " + ITEMS + |
29 |
> |
" PRODUCERS: " + PRODUCERS + |
30 |
|
" CONSUMERS: " + CONSUMERS + |
31 |
|
" CAP: " + CAP); |
32 |
|
long nitems = (long)ITEMS * PRODUCERS * CONSUMERS; |
47 |
|
static final class Sub implements Flow.Subscriber<Boolean> { |
48 |
|
int count; |
49 |
|
Flow.Subscription subscription; |
50 |
< |
public void onSubscribe(Flow.Subscription s) { |
51 |
< |
(subscription = s).request(CAP); |
50 |
> |
public void onSubscribe(Flow.Subscription s) { |
51 |
> |
(subscription = s).request(CAP); |
52 |
|
} |
53 |
< |
public void onNext(Boolean b) { |
53 |
> |
public void onNext(Boolean b) { |
54 |
|
if (b && (++count & ((CAP >>> 1) - 1)) == 0) |
55 |
|
subscription.request(CAP >>> 1); |
56 |
|
} |
57 |
< |
public void onComplete() { |
57 |
> |
public void onComplete() { |
58 |
|
if (count != ITEMS) |
59 |
|
System.out.println("Error: remaining " + (ITEMS - count)); |
60 |
< |
phaser.arrive(); |
60 |
> |
phaser.arrive(); |
61 |
|
} |
62 |
|
public void onError(Throwable t) { t.printStackTrace(); } |
63 |
|
} |
64 |
|
|
65 |
|
static final class Pub extends RecursiveAction { |
66 |
< |
final SubmissionPublisher<Boolean> pub = |
66 |
> |
final SubmissionPublisher<Boolean> pub = |
67 |
|
new SubmissionPublisher<Boolean>(ForkJoinPool.commonPool(), CAP); |
68 |
|
public void compute() { |
69 |
|
SubmissionPublisher<Boolean> p = pub; |
70 |
|
for (int i = 0; i < CONSUMERS; ++i) |
71 |
|
p.subscribe(new Sub()); |
72 |
< |
for (int i = 0; i < ITEMS; ++i) |
72 |
> |
for (int i = 0; i < ITEMS; ++i) |
73 |
|
p.submit(Boolean.TRUE); |
74 |
|
p.close(); |
75 |
|
} |